Question

Is it possible to create index on name field in fruit subdocument ?

{                                                                               
    "trees": 5,
    "fruit":[{"name":"apple", "color":"red"}, {"name":"pear", "color":"green"}]
}
Was it helpful?

Solution

db.yourCollection.ensureIndex({"fruit.name":1})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top