我有一个出版物应该返回给我所有匹配的用户_id
大批。这是查询:
Meteor.users.find({
'_id': { $in: myArray}},{
'profile.name':1,
'profile.description':1,
'profile.picture':1,
'profile.website':1,
'profile.country':1}
);
当我在 Robomongo(mongo 浏览器)中运行它时,它可以工作。但我的出版物只返回undefined
。当我console.log(myArray);
在出版物中,我得到这样的东西['FZ78Pr82JPz66Gc3p']
。这是我粘贴到我的工作 Robomongo 查询中的内容。
替代问题:我怎样才能从Collection.find()
result?
看起来您正在尝试在您的find,你可以这样做:
var options = {
fields: {
'profile.name': 1,
'profile.description': 1,
'profile.picture': 1,
'profile.website': 1,
'profile.country': 1
}
};
Meteor.users.find({_id: {$in: myArray}}, options);
但是,如果这是在发布功能中使用的,我strongly建议仅使用顶级字段,如下所示:
Meteor.users.find({_id: {$in: myArray}}, {fields: {profile: 1}});
有关原因的更多详细信息,请参阅这个问题.
对于第二个问题,您可以通过调用查看游标返回的文档fetch在上面。例如:
console.log(Posts.find({_id: {$in: postIds}}).fetch());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)