MongoDB db.collection.count () vs db.collection.find (). Length ()

I would like to understand why these commands mongosreturn different numbers when running from an instance against the same MongoDB collection?

  • db.users.count()
  • db.users.find().length()

What could be the reason and could it be a sign of major problems?

+4
source share
1 answer

I believe your collection is sealed.

Most decisions with roundabout databases have such a discrepancy due to the fact that some teams review the entire collection, i.e. all documents of all fragments, while some other teams consider only the fragment documents to which it is connected.

This must always be remembered. This mainly applies to teams that:

  • amount
  • ,
  • ,
  • ...

Mongo docs:

count() db.collection.find(query).count() ....

db.collection.count() , ....

, Mongo , Mongo , , .

, , , , .

nosql DB .

+1

All Articles