SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

Why does `count` perform query collection? #108

Closed mingfang closed 8 years ago

mingfang commented 8 years ago

According there https://softinstigate.atlassian.net/wiki/display/RH/Query+Documents#QueryDocuments-Counting, the count parameter queries the collection, twice. why? The mongodb documentation clearly states that count() does not query at all, https://docs.mongodb.org/v3.0/reference/method/db.collection.count/.

Is there a way to execute the native mongodb version of count()?

ujibang commented 8 years ago

RESTHeart actually performs the count using the "nativa mongodb version of count()"

see public long getCollectionSize(final DBCollection coll, final Deque<String> filters) in CollectionDAO

so, in order to add the collection size to the response, it needs to execute two queries: