是否可以在name
子文档中的fruit
字段上创建索引?
{
"trees": 5,
"fruit":[{"name":"apple", "color":"red"}, {"name":"pear", "color":"green"}]
}
答案 0 :(得分:3)
db.yourCollection.ensureIndex({"fruit.name":1})