Mongodb check existence count vs findOne performance
There are some situations where count
can give you inaccurate results. Also, the performance would be slower than the findOne()
.
On a sharded cluster, db.collection.count() can result in an inaccurate count if orphaned documents exist or if a chunk migration is in progress.
After an unclean shutdown of a mongod using the Wired Tiger storage engine, count statistics reported by count() may be inaccurate.
As you are really looking to check the existence of the document, I think findOne()
is the better option.