Using same key twice in MongoDB

In MongoDB course one of my colleague has run a query with two occurrences of same key. Then I thought query will fail on validation. But the way that MongoDB behaves is different on this scenario.
<div>
</div><div><div>> </div><div>> db.test.insert ({name:1})</div><div>> db.test.insert ({name:2})</div><div>> db.test.insert ({name:3})</div><div>> db.test.insert ({name:4})</div><div>> </div><div>> db.test.find({name:1,name:2})</div><div>{ “_id” : ObjectId(“518342a1f193f1de8aef117e”), “name” : 2 }</div><div>> </div><div>> db.test.find({name:3,name:1})</div><div>{ “_id” : ObjectId(“5183429ef193f1de8aef117d”), “name” : 1 }</div><div>> </div></div><div>
</div><div>Then I ran some insert statements.</div><div>
</div><div><div>> </div><div>> db.test.insert ({name:”Dedunu”,name:”Dinesh”})</div><div>> </div><div>> db.test.find()</div><div>{ “_id” : ObjectId(“51833fabeadc78fbf0f7232d”), “name” : “Dinesh” }</div><div>> </div></div><div>
</div><div>I think this behavior is inherited from JavaScript. </div>

Tags

  • MongoDB
  • mongo
  • Mongo Shell