我在查询某些内容时遇到了问题。Meteor Mongo查询集合中数组的子集
我有一个名为Guestlists的包含guestlist的集合。每个元素包含一个日期和其他一些东西以及一个名为“list”的数组。 “list”数组包含每个访客列表条目的元素。每个访客列表条目都有一个“entryOwner”,意思是将条目添加到列表中的人员。
这里是架构:
Schemas.Guestlist = new SimpleSchema({
_id: { type: String, regEx: SimpleSchema.RegEx.Id },
date: { type: Number },
promoters: { type: [String], regEx: SimpleSchema.RegEx.Id, defaultValue: [] },
list: { type: Array, defaultValue: [] },
'list.$': { type: Object },
'list.$.name': { type: String },
'list.$.entryOwner': { type: String },
'list.$.comment': { type: String, optional: true },
'list.$.accepted': { type: Boolean, defaultValue: false },
'list.$.rejected': { type: Boolean, defaultValue: false },
})
现在问题来了。我想查询数据库,并获得1个访客列表,只有特定用户ID的访客列表条目。
这是我的尝试:
Guestlists.find({_id : guestlistID, list: {$elemMatch: {entryOwner: user._id}}}, {fields: { 'list.$': 1}})
但是,只有一个项目返回guestlist的“清单”阵列,这是第1英寸我如何获得具有我查询的entryOwner的'list'中的所有项目?
也试过这个,但给同样的结果:
Guestlists.find({_id: guestlistID}, {fields: {list: {$elemMatch: {entryOwner: user._id}}}})
同样重要的是TA保持它作为一个游标,因为我想在我的出版物
不,这不是我所期待的,找到它。很快就会发布! –