My document has the format as show below:
{
"_id":ObjectId("4fabcd13"),
users:[
{id:"001", tags:["friend", "buiz"]},
{id:002, tags:["relationship"]}
]
},
{
"_id":ObjectId("4fabcd14"),
users:[
{id:"003", tags:["buiz"]},
{id:002, tags:["friend"]}
]
},
Can I let MongoDB index on users.tags element? I had tried the use following statement but failed:
db.invoices.ensureIndex({user.tags:1})
Thanks a lot!
I think you just missed the quotes (because of the dot in the field name), and the field is called “users”, not “user”: