问题
I have a mango query:
{
"selector": {
"age":{
"$eq": 22
}
}
}
I want to know the number of documents that satisfy this criteria.
I know we can use map reduce functions to achieve this, but is there any way to do this by using mango query like using some key like "count" in the query itself as we do for "sort", and "fields".
I am firing mango query through rest client and I want the number of documents as the response of the query.
回答1:
It is not really possible to retrieve the full number of documents by using the find function. By default _find is limited to 25 documents to be returned (http://docs.couchdb.org/en/2.0.0/api/database/find.html).
limit (number) – Maximum number of results returned. Default is 25. Optional
By increasing this number, the response time is increasing. Having e.g. 15.000 entries in your couch database and limiting the query to 999999 would result in a long waiting time.
Back to your question: after receiving your result set, simply run something like array.length
to count your results.
回答2:
CouchDB returns an object. In this object you'll find an array "docs". Just get the length of this array and you'll have the number of returned documents.
来源:https://stackoverflow.com/questions/43657749/how-to-count-the-documents-returned-by-a-mango-query