support COUNT of a query on a partitioned collection
db.collection.count() works just find but when attempting to count a filtered down collection db.collection.find({query...}).count() results in an Operation Failure that says 'query in command must target a single shard key' but need to be able to do counts across multiple partitions

This feature is now available. To learn more about this feature and our overall wire protocol support for MongoDB API please see, https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support.
Thank you for your suggestion and votes.
27 comments
-
Masood, Raas commented
need this :(
-
Gavin commented
This is NOT completed.
Now we can't query count in a single partition unless we add the partition key to the where clause.
This means that working around the other thing that is not completed, skip and take, is not possible unless we write two queries, one of which has an extra where clause.
-
Haider Shahid commented
Still getting the same error with Cosmos Mongo.
-
Daniel Vazquez Jimenez commented
Hello,
The main question said: "need to be able to do counts across multiple partitions"
In my case i need the operation with the next query, because many clients need a total count of documents:
db.collection.find({query...}).count()
If i use aggregation pipeline the RUs is very expensive, how I said in other comment:
- aggregation consumes more than 30k RUs (with 50k of documents) with match , order and count.
I hope that soon will be possible do this count operation with cross partition.
I believe the status of this feature should not be 'finished', honestly
-
Cristina commented
Hello. When will it be available for cross-partition queries?
-
Hello. Yes the query should work. Keep in mind this is not a cross-partition query. Only in partition at this time.
-
proxy commented
Hi ADMIN, you said that this feature is now avaiable, does this mean db.collection.find({query...}).count() can work?
-
Peter commented
Hi Azure team, any update??
-
Richa Garg commented
Hi Azure team . I need to query count with filters . I see the issue 'query in command must target a single shard key' still exists . Can you please let me know if this is still work in progress ?
-
Anonymous commented
Hi Admin, Can we know the exact release date of the api.we need it
-
Sachin commented
This is really needed. As a workaround since I am only interested in counts for investigative purposes against a DB, I use `db.vacancies.find().toArray().length` in a MongoShell/Robo3T
-
Pablo Mario Everis commented
This suggestion is really necessary
-
David aguado commented
Great idea
-
Daniel Vázquez Jiménez commented
Currently I make this query with aggregation and consumes more than 30k RUS (50k documents) with match, order and count.
This means that we constantly get many errors type: Request rate large.
This feature is very necessary.
-
Prasanna Kumari commented
This is a required feature and will be very useful.
-
alex commented
similarly, can you address it for .remove({}) ?
-
Abe commented
This is a huge shortcoming that is preventing Cosmos from being a real player in the cloud database field. Please address it as quickly as possible.
-
alex commented
This needs to get fixed.
With the SQL API, you can Enable Cross Partition Queries.
We either need this to work out of the box for the Mongo API or some way to override the restriction similar to the above flag.
-
Mile commented
This is MAJOR
-
Jeff commented
This was a major let down.