[SERVER-6899] Inability to find a document in the collection, if the find-query containes the fields not in the same order as they are in the collection. Created: 30/Aug/12  Updated: 15/Feb/13  Resolved: 30/Aug/12

Status: Closed
Project: Core Server
Component/s: Querying, Shell
Affects Version/s: 2.0.7
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Alexander Assignee: Unassigned
Resolution: Done Votes: 0
Labels: find, query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 12.04 LTS 32 bit


Operating System: Linux
Participants:

 Description   

Example:
> db.createCollection('testCol')

{ "ok" : 1 }

> db.testCol.insert({fish: {name: 'Arctic fish', desciption: 'I like cold water!'}})

And now we a going to find our recond.
> db.testCol.find({fish: {name: 'Arctic fish', desciption: 'I like cold water!'}})
{ "_id" : ObjectId("503f37b12f2ef2c8d4b9a430"), "fish" :

{ "name" : "Arctic fish", "desciption" : "I like cold water!" }

}

But if we define fields in other order, mongo can't find our record.
> db.testCol.find({fish:

{desciption: 'I like cold water!', name: 'Arctic fish'}

)



 Comments   
Comment by Scott Hernandez (Inactive) [ 30/Aug/12 ]

You want to use dot-notation because the document is compared as a whole, not in parts nor out of order.

db.testCol.find({"fish.desciption": 'I like cold water!', "fish.name": 'Arctic fish'})

http://www.mongodb.org/display/DOCS/Dot+Notation+(Reaching+into+Objects)

Generated at Thu Feb 08 03:13:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.