Javascript 运算符中的MongodB在不应返回的空白数组上返回
我在客户端上运行的coffeescript中有一个模板函数:Javascript 运算符中的MongodB在不应返回的空白数组上返回,javascript,mongodb,coffeescript,meteor,Javascript,Mongodb,Coffeescript,Meteor,我在客户端上运行的coffeescript中有一个模板函数: Template.leftNav.starred = () -> user = Meteor.user() if ! user return else starredPages = user.profile.starredPages starred = Entries.find({ _id :{in: starredPages}}).fetch() Mete
Template.leftNav.starred = () ->
user = Meteor.user()
if ! user
return
else
starredPages = user.profile.starredPages
starred = Entries.find({ _id :{in: starredPages}}).fetch()
Meteor.user()
返回
Object {_id: "AHSwfYgeGmur9oHzu", profile: Object}
_id: "AHSwfYgeGmur9oHzu"
profile: Object
starredPages: Array[4]
0: "asdasdasdasdasd"
1: "abc123"
2: "blobby"
3: "bxSbMgszYxbCqDonF"
和Meteor条目。查找({})
返回:
Entries
Meteor.Collection {_makeNewID: function, _transform: null, _manager: Meteor._LivedataConnection, _collection: LocalCollection, _name: "entries"…}
_collection: LocalCollection
_savedOriginals: null
docs: Object
Wkxxpapm8bbiq59ig:
_id: "M3vDJNMZJjBDfrc7D"
bxSbMgszYxbCqDonF:
_id: "bxSbMgszYxbCqDonF"
在模板函数中执行代码:
starredPages = user.profile.starredPages
starred = Entries.find({ _id :{in: starredPages}}).fetch()
starred
返回为空白数组,即使starredPages数组中的bxSbMgszYxbCqDonF
值与Entries.docs
集合数组中的\u id
值匹配
这是为什么?如何使它返回
星号页面
数组和\u id
之间的匹配?您需要使用$in
starred = Entries.find({ _id :{$in: starredPages}}).fetch()
简单打字;)