2012-04-13 48 views
0

我的文档的格式为显示如下:如何在grandchild元素上索引,当它的父元素和它本身都是MongoDB中的数组时?

{ 
    "_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"]} 
    ] 
}, 

我可以让users.tags元素MongoDB的指数?我曾尝试下面的语句使用,但失败:

db.invoices.ensureIndex({user.tags:1})

非常感谢!

回答

1

我认为你错过了引号(因为字段名点),以及该领域被称为“用户”,而不是“用户”:

db.invoices.ensureIndex({"users.tags":1}) 
相关问题