如何从对象数组中使用$ in获取数据?

时间:2017-08-28 12:38:08

标签: mongodb

我有像

这样的数据库
 "profile" : {
    "firstName" : "dh",
    "lastName" : "french",
    "roles" : [ 
        "applicant"
    ]
},

我想找到谁的角色是applicant 所以我试试这个查询

 var data = Meteor.users.find({
        "profile.roles": { $in: ["applicant"] }
    }).fetch();

但我总是获得0长度数据 那么,哪个查询是正确的

1 个答案:

答案 0 :(得分:2)

在这种情况下,您不需要使用 Meteor.users.find({ "profile.roles": "applicant" }).fetch(); 运算符。采取很容易:

selectedPersons = Person;