Hi
I want to get the count of total records in a collection w.r.t to a filter so for that I typed the query in Robo 3T as db.collectionA.find({"userId":"u123"}).count()
and it works fine for me and show the output.
But when I moved to MongoDB Compass
i was confused that where to write the count clause, can anybody help me to do this?
The size of the collection might be the reason then. It’s possible that the count times out. You can try expanding the query bar by clicking on Options. On the bottom right, you’ll be able to set maxTimeMS. By default, it’s set to 5000 but you can increase it.
Hi, you don’t need to specify the “count” clause explicitly in Compass UI. Simply put filter criteria and hit enter - it would return all the values matching that criteria and would show:
Displaying documents 1-20 of 150
Assuming, there were 150 records that matched your filter criteria.
However, as suggested by @Massimiliano_Marcon - please click to expand the OPTIONS button and try increasing the MAXTIMEMS from 5000 to 10,000 or something and then see. You could even try combination of SKIP and LIMIT if the data set count returned from your query criteria is extremely very large number.
Otherwise, simply use the MongoDB shell that comes with new version of Compass UI and write the same query that you would use with Robo3T.
Thanks @ManiK for detailed message.
The thing is that we have some limitation by the client that we can only do queries via Mongo Compass & it’s version is 1.19.X. we can’t update it.
Secondly we have hundred and thousands of documents in a collection so it show N/A instead of total document count. (check this image)
The solution is that I have around 10000000+ documents in a collection and as @Massimiliano_Marcon and @ManiK said that increase the MAXTIMEMS limit so I did the same step and got the solution.