Querying CouchDB documents between a start date and an end date

后端 未结 4 1183
萌比男神i
萌比男神i 2020-12-14 20:02

I\'ve been trying to figure out how to create a CouchDB view that will let me query all the documents that have a start date greater than A and an end date less than B.

4条回答
  •  眼角桃花
    2020-12-14 20:09

    Just create a map like this:

    function (doc) {emit(doc.timestamp, 1)}
    

    then query the view with:

    ?descending=true&limit=10&include_docs=true // Get the latest 10 documents
    

    The view will be sorted oldest to latest so descending=true reverses that order.

    If you want a specific range.

    ?startkey="1970-01-01T00:00:00Z"&endkey="1971-01-01T00:00:00Z"
    

    would get you everything in 1970.

    These should help:

    • http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
    • http://wiki.apache.org/couchdb/HttpViewApi
    • http://wiki.apache.org/couchdb/View_collation

提交回复
热议问题