Taking current time in couchbase view

Date().getTime() is not a deterministic function (meaning it returns a different value given the same parameters at each call). In this case It is evaluated at the time of indexing the item which can be arbitrary amount of time after the item is mutated depending on your view settings. However it is NOT reevaluated over time. To get this to work correctly, you should index all documents and query items created in the last hour during query time;

function (doc, meta) {
if(meta.id.indexOf(‘media’)>-1 && doc.digest_notification == 1 )
emit(doc.created_at, doc)
}

and query the view with startKey with the value of Date().getTime()-3600000.
thanks
-cihan

1 Like