我在流星中使用现有的Mongodb。我不知道如何使用$in
ObjectId()
Users = new Mongo.Collection('users', {idGeneration: 'MONGO'});
var ids = ['55549158f046be124e3fdee7',
'5539d937f046be0e2502aefc',
'55548e10f046bee14c3fdeed',
'55549938f046be99493fdef8' ];
Users.find({_id:{$in: ids}}).fetch(); //returns empty array
答案 0 :(得分:1)
您可以先使用 map()
方法将数组ID转换为ObjectIds数组:
var Users = new Mongo.Collection('users', {idGeneration: 'MONGO'}),
ids = [
'55549158f046be124e3fdee7',
'5539d937f046be0e2502aefc',
'55548e10f046bee14c3fdeed',
'55549938f046be99493fdef8'
],
mids = ids.map(function(id) { return new Mongo.ObjectID(id); });
Users.find({"_id":{"$in": mids}}).fetch();