Node.js Date object’s represent time in milliseconds as opposed to the seconds you receive in a unix timestamp. So in your case, you’re actually looking to do something like this:
> new Date(1597423505 * 1000)
2020-08-14T16:45:05.000Z
then how to set the current timestamp to expiry in one day?
bucket.insert(
id,
{ ...data, ...body },
{ expiry: what to set here to make document expiry in 1 day },
(error) => {
if (error) reject(error);
else resolve({ id });
}
);
For Couchbase SDKs which accept simple integer expiry values (as opposed to a proper date or time object) allow expiration to be specified in two flavors.
As an offset from the current time.
As an absolute Unix time stamp
If the absolute value of the expiry is less than 30 days ( 60 * 60 * 24 * 30 seconds), it is considered an offset . If the value is greater, it is considered an absolute time stamp .
It might be preferable for applications to normalize the expiration value, such as by always converting it to an absolute time stamp. The conversion is performed to avoid issues when the intended offset is larger than 30 days, in which case it is taken to mean a Unix time stamp and, as a result, the document will expire automatically as soon as it is stored.
Just to add to @vsr1’s answer: Node.js deals with dates almost entirely in terms of ‘milliseconds since epoch’, where as standard unix timestamps are ‘seconds since epoch’. So in your case, again you need to perform that conversion:
// Using Dates's directly:
expiry: (new Date()).getTime() / 1000
// Since I saw you are using moment:
expiry: moment().add(40, "days").unix()