我在查詢某些內容時遇到了問題。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保持它作爲一個遊標,因爲我想在我的出版物
不,這不是我所期待的,找到它。很快就會發布! –