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

{                                                                               
    "trees": 5,
    "fruit":[{"name":"apple", "color":"red"}, {"name":"pear", "color":"green"}]
}
有帮助吗?

解决方案

db.yourCollection.ensureIndex({"fruit.name":1})
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top