i have a structure of document in mongodb as below
{
"_id": "some_id",
"key1": "value1",
"key2": "value2",
"key3": [
{"subkey1":"subval1", "subkey2":"subval2", "subkey3":"subval3"},
{"subkey1":"subval11", "subkey2":"subval21", "subkey3":"subval31"},
{"subkey1":"subval12", "subkey2": "subval22", "subkey3":"subval32"}
],
"key4": "value4"
}
and i want to put index on “subkey1”. how to do it???
or is it not possible(in this case is it work that much efficiently with the index on “key3”)???
just use ensureIndex to add an index to the key you want
as indicated in the docs:
adding an index to key3 alone, would not be used if you query using “key3.subkey1”.