A. How do I index "nested" and all of it's values?
B. How do I index valuetwo?
{
id: 00000,
attrs: {
nested:{
value: value1,
valuetwo: value2,
}
}
}
I've looked here: http://www.mongodb.org/display/DOCS/Indexes, and the docs to my knowledge, aren't clear about indexing things that aren't nested.
A. to index all the properties in "nested" you will have to index them separately:
This can be done in one command with:
B. to index just "valuetwo":
Use createIndex over ensureIndex as ensureIndex is Deprecated since version 3.0.0
MongoDB automatically creates a multikey index if any indexed field is an array; you do not need to explicitly specify the multikey type.
This will work for both the scenario's db.coll.createIndex( { "addr.pin": 1 } )
Scenario 1 nested OBJECTS
Scenario 2 nested Arrays
https://docs.mongodb.com/manual/core/index-multikey/
You'd create them just as if you were creating an index on a top level field:
You do need to explicitly create indexes on each field.