Querying CouchDB documents between a start date and an end date

后端 未结 4 1175
萌比男神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:21

    Use an array key in your map function

    function (doc) {
      var key = [doc.start, doc.end]
      emit(key, doc)
    }
    

    Then to get documents with a start date greater then 1970-01-01T00:00:00Z and an end date before 1971-01-01T00:00:00Z use the query

    ?startkey=["1970-01-01T00:00:00Z", ""]&endkey=["\ufff0", "1971-01-01T00:00:00Z"]
    

提交回复
热议问题