Filtering data based on datetime

Hi,
Is there an option of filtering data using views based on current datetime
For ex. I've many JSON Document each of these document contains a key:value as
Starttime:2013-08-25T13:41:13.163+01:00.

I would like to filter those documents whose Starttime is less than current time. Is there a way I can achieve this using view.

Thanks

2 Answers

« Back to question.

Hello,

Suppose you have a document like this one:

{
  "type": "product",
  "date": "2013-08-25T13:41:13.163+01:00"
}

If you want to do some queries on the date, you need to create a view to index the date, and use a compound key:

function (doc, meta) {
  emit(  dateToArray(doc.date));
}

This will generate an index based on the date that is like the following:

[2013,8,25,12,41,13]

So if you want to get all the document id where the date is "before" August 25 , you have do to this query"

?startkey=[2013,8,25,23,59,59]&descending=true

Regards
Tug
@tgrall

« Back to question.

Couchbase has a great builtin datetime into array function for the mapper

http://www.couchbase.com/docs/couchbase-manual-2.1.0/couchbase-views-wri...

from here you can put the key into start and end range in your view query.

http://www.couchbase.com/docs/couchbase-manual-2.1.0/couchbase-views-wri...