{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 2,
...
}
Instead, the index keys are the entire embedded document, and field order matters:
> db.test.find({ "x" : { "a" : 1, "b" : 2 } })
{ "_id" : ObjectId(...), "x" : { "a" : 1, "b" : 2 } }
> db.test.find({ "x" : { "a" : 1, "b" : 2 } }).explain()
{
"cursor" : "BtreeCursor x_1",
"isMultiKey" : false,
"n" : 1,
...
"indexBounds" : {
"x" : [
[ { "a" : 1, "b" : 2 },
{ "a" : 1, "b" : 2 }]
]
},
...
}
> db.test.find({ "x" : { "b" : 2, "a" : 1 } })
{ "_id" : ObjectId(...), "x" : { "b" : 2, "a" : 1 } }
To summarize by answering your question about how to know what fields are indexed, the fields that are indexed are precisely the fields you specify in the index command. For a field that has values that are embedded docs, this means the indexed value is the embedded document. If you want to index a subfield of an embedded document, use dot notation. For example, to create an index to fulfill the first query in the example
db.test.find({ "x.a" : 1, "x.b" : 2 })
create an index on { "x.a" : 1, "x.b" : 1 } or { "x.b" : 1, "x.a" : 1 }.
-Will