find() and findOne() methods in MongoDB showing different results
<p>I have a Mongo database where in the users collection I have just 1 document.
I do a <code>find()</code> and a <code>findOne()</code> operations using the username filter.
I get what I think is an incorrect result from <code>find()</code> operation.</p>

<pre><code>MongoDB shell version: 3.2.10
connecting to: test
Server has startup warnings: 
2016-10-20T20:37:32.681-0700 I CONTROL  [initandlisten] 
2016-10-20T20:37:32.681-0700 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-10-20T20:37:32.681-0700 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-10-20T20:37:32.681-0700 I CONTROL  [initandlisten] 
2016-10-20T20:37:32.681-0700 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-10-20T20:37:32.681-0700 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-10-20T20:37:32.681-0700 I CONTROL  [initandlisten] 
&gt; use lab2
switched to db lab2
&gt; db.users.find()
{ "_id" : ObjectId("5807ac0765f24dd0660e4332"), "username" : "avtrulzz", "fname" : "Abc", "lname" : "Def", "email" : "test@yahoo.co.in", "password" : "rootuser", "mobile" : NumberLong(1234567890) }
&gt; db.users.findOne()
{
    "_id" : ObjectId("5807ac0765f24dd0660e4332"),
    "username" : "avtrulzz",
    "fname" : "Abc",
    "lname" : "Def",
    "email" : "test@yahoo.co.in",
    "password" : "rootuser",
    "mobile" : NumberLong(1234567890)
}
&gt; if (db.users.find({username : "noSuchUsername"})) {
... print ("Username exists"); 
... } else {
... print ("User does not exist"); }
Username exists
&gt; if (db.users.findOne({username : "noSuchUsername"})) { print ("Username exists");  } else { print ("User does not exist"); }
User does not exist
&gt; if (db.users.findOne({username : "avtrulzz"})) { print ("Username exists");  } else { print ("User does not exist"); }
Username exists
</code></pre>

<blockquote>
  <p></p>
</blockquote>

<p>See the <code>find()</code> operation is returning user exists which is not true. <code>findOne()</code> is behaving correctly.<a href="https://i.stack.imgur.com/Q6nIn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Q6nIn.png" alt="enter image description here"></a></p>