I would like to know if there is some improvement on MongoCollection::findOne or if is just an “alias” or “shorcut” to MongoCollection::find with a limit of 1, for example.
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
findOne()is an alias offind()with alimit(-1)You can see this in the source code here. It does the equivalent to
find(...).limit(-1).getNext().The -1 is actually relevant. Here’s a snippet from the wire protocol docs:
If you go to the shell and type
> db.collection.findOne(no parens), you can see that the function is also just a helper in the shell.So, “yes
findOne()is just a helper”.