Pergunta

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

{                                                                               
    "trees": 5,
    "fruit":[{"name":"apple", "color":"red"}, {"name":"pear", "color":"green"}]
}
Foi útil?

Solução

db.yourCollection.ensureIndex({"fruit.name":1})
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top