1

I am using spring data to fetch couchbase documents. I assume the document expiry cannot be set as a configurable value externalized in a property file (@Document(expiry = )) based on answer in this link

However can I define a view in cochbase and have query to return only the documents which have been created in the past 15 minutes? I don't want to save additional information regarding date in my document and I am looking to see if there is any meta data that can be used for this purpose

   function (doc, meta) {
    if(doc._class=="com.customer.types.CustomerInfo" ){
      emit(meta.id, doc);
    }
   }
Community
  • 1
  • 1
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315

1 Answers1

4

If you go into the webconsole and create a development view, you can have a look at what metadata are available using the preview:

emit(meta.id, meta)

This gives us

{
  "id": "someKey",
  "rev": "3-00007098b90700000000000002000000",
  "seq": "3",
  "vb": "56",
  "expiration": 0,
  "flags": 33554432,
  "type": "json"
}

So as you can see, there is no explicit metadata that you can use to tell if a doc has been created/updated in the last 15 minutes.

Side note: the id of the doc will always be part of the view's response so emitting it is a bit redundant. More importantly, don't emit the whole doc as a value (if in doubt on what to emit as the second field, just emit null). This value field is stored in the index, so that means that you are basically storing your document's content twice (once in the primary store, once in the view index)!

Simon Baslé
  • 27,105
  • 5
  • 69
  • 70