Setting expiry time on upsert call causes couchbase to silently fail creating document


#1

I originally created a document using upsert with no expiry time set and the document was created successfully. I then tried setting an expiry time of 30 seconds (using epoch timestamp) and using upsert on the same document and it deleted the document. I tried using upsert to create a new document with an expiry time of 30 seconds and it never created it. I’m using couchbase nodeJS SDK 2.1.1. There are no errors reported, and the result of the upsert call when logged is: { cas: CouchbaseCas<10068523169580844800> } (I can’t do much deeper logging or I get Illegal Invocation exceptions on the CAS object).

My code looks like this:

var authCodeModel = utilGeneral.copyDataModel('authorizationCode', dataModels);
authCodeModel.userId = userId;
authCodeModel.redirectionUri = redirect_uri;
authCodeModel.clientId = client._id;
authCodeModel.createdAt = (new Date()).toISOString();
var docId = constants.dataModelIdPrefixes.authorizationCode + userId+'::'+client._id;

var expiryTime = new Date();
var options = {
     expiry: expiryTime.getTime()+globals.authorizationCodeLifetimeInMS
};

authDbConnection.upsert(docId, authCodeModel,options, function(err,result) {
    if (err) {
        logger.error("Failed to create authorizationCode doc");
        return callback(err);
    }

    console.log("auth code generation result: ", result);
    return callback(null, docId);
});

If I log options.expiry I can see that it is correctly being set to 30 seconds in the future. E.g. The log showed:

2015-09-30T17:52:02.465Z DEBUG - New authcode doc will expire at:  1443635582465

How can I get upsert to correctly set the expiry time? For a different doc type I want an expiry of a year, so I can’t specify in seconds for that one.


#2

If I specify in seconds it works. So it looks like the documentation is incorrect or there’s a bug. The page here: http://docs.couchbase.com/admin/admin/Concepts/concept-docExpiration.html
Says you can specify the time in epoch time, or in seconds if it’s less than 30 days. But you can’t actually specify the time in epoch time if it’s less than 30 days you can only specify it in seconds. It would be nice if it accepted epoch time for both cases since that way the client doesn’t have to write custom logic to change the value sent in based on how long it is.