Reputation: 75
I'am working on Cloudant NoSQL database, the data is received every 15 seconds, so in every 5 mins there will be 20 documents on the database.
I need to get documents which have a difference in timestamp of five minutes for example, Document with time stamp:"2017-03-14 T 18:21:58"
and
Document with time stamp:"2017-03-14 T 18:26:58"
and so on...
Sample document:
Upvotes: 0
Views: 274
Reputation: 3737
Make a view keyed on the timestamp. I interpret your question as "get all 20 documents sharing a particular timestamp". If that's the case you can get away with not parsing the timestamp:
function(doc) {
if (doc && doc.timestamp) {
emit(doc.timestamp, 1)
}
}
You can now query the view:
% curl 'https://USER:[email protected]/DATABASE/_design/DDOC/view/VIEWNAME?key=TIMESTAMP&include_docs=true&limit=20'
Substitute the uppercase bits to the relevant names and parameters for your system.
If you need finer granularity for your query (time series style), there is an old-but-useful blog from one of the Cloudant founders on the topic here: https://cloudant.com/blog/mapreduce-from-the-basics-to-the-actually-useful/
Upvotes: 2