My problem is: There is a collection of users. Im trying to find, does user with _id=xxx has somevalue > 5.
I’m wondering, what will be faster, using find(...).count() > 0 or findOne(...) != null? Or maybe there is some other, faster/better way?
The difference between the query times should be almost negligible, because they both limit the bounds of the unique _id, so they will be found immediately. The only slight edge here goes to the
countbecause the db will return a int instead of an entire document. So the time you save is purely because of the transfer of the data from db to client.That being said, if your goal is to do an exists query and you don’t care about the data, use the
count