I need a way to make sure there are no docs created without an expiration. I obviously am a newbie expecting this to work. Is this even possible? Any suggestions? Is there a way to disallow docs without expiry?
function (doc, meta) {
if (meta.expiration == 0){
emit(doc.id, meta.expiration);
}
}
What you have there will not mutate the source document. It will just write it into the view (which is separate storage).
There is no in-situ validation. That’s somewhat intentional, as validation can get complex and therefore expensive, though the case you have is pretty simple.
If you wanted a mutate-after-finding-invalid, you could use Couchbase Eventing. Or, you could maintain either a view index or a GSI index to query with N1QL to find things that are invalid and modify their ttl with touch()
.