> So it's not obvious right off the top, but these are actually two different
> queries:
Yes, I see that now. In my case its OK, as I only store and query off
those two fields. But yes, its important to remember that.
This is documented at
http://www.mongodb.org/display/DOCS/Dot+Notation+%28Reaching+into+Objects%29
under "Dot Notation vs. Subobjects" -
"To match only objects with these exact keys and values, we use an
object:
db.blog.findOne({"author" : {"name" : "Jane", "id" : 1}})
Note that
db.blog.findOne({"author" : {"name" : "Jane"}})
will not match, as subobjects have to match exactly (it would match an
object with one field: {"name" : "Jane"}). "
So my current take-away: use the declarative dot-notation version, so:
db.users.find({'
ext_id.id':"6708526", 'ext_id.type':1}).explain()
Thanks for looking into this.
On Apr 14, 4:39 pm, Gaetan Voyer-Perrault <
ga...@10gen.com> wrote:
> So it's not obvious right off the top, but these are actually two different
> queries:
>
> (1) db.users.find({'
ext_id.id':"6708526", 'ext_id.type':1})
> (2) db.users.find({'ext_id':{'id':"6708526", 'type':1}})
>
> Query #1 would match the following document; #2 would not. (*note the extra
> field*)
> users : {
> first_name: "Foo",
> ext_id: {
> id: "6708526",
> type: 2,
> name : 'test'
> }
>
> }
>
> ===
> The following build two different indexes
> (a) db.users.ensureIndex({'ext_id <
http://ext_id.id/>':1})