這個問題讓我發瘋。我需要Meteor.publish中的代碼來獲得非空的對象數組。流星發佈獲取非空陣列
樣本結構(這裏字段名是任意的,我只是呈現結構)圖所示 -
Books:{
_id:'xyz',
name:'book1',
image:[binary array],
pages:[
{
id:1,
name:'page1',
author:'ueye',
picture:[binary array]
chapters:{
mon:[
{
chapter1:'zzz',
chapter2:'xxx'
}
],
tue:[
{
chapter1:'123',
chapter2:'yyy'
}
],
wed:[],
thu:[],
fri:[],
wkd:[],
}
},
{
id:2,
name:'page2',
author:'asfnwro',
picture:[binary array],
chapters:{
mon:[
{
chapter1:'xyz',
chapter2:'uuu'
}
],
tue:[],
wed:[
{
chapter1:'7777',
chapter2:'ieismxi',
}
],
thu:[],
fri:[],
wkd:[],
}
}
]
}
在這個例子中,你看,我有一個「星期二」空數組(看結束)。我想獲取所有不爲空的'chapters.tue'。 請注意,我不希望僅整個文檔(在此示例中)爲'pages.id','pages.name','pages.picture'和所有來自'chapters.tue'的字段用於這些數組('chapters.tue ')不是空的。 確保章節在每週的每一天都會有數組,但這些數組本身可能有也可能沒有元素。當這些數組填充時,結構總是相同的(在上例中,您將始終擁有chapter1,並且您將始終擁有數組中的chapter2)。
謝謝你的幫助。
不能使用蒙戈聚集一起來看流星發佈,只有流星方法 – Khang
那麼任何建議,我怎麼能完成以上流星發佈? – RichardAu
我認爲你應該分開你的收藏,創建三個獨立的集合:'myDoc','pages','bags' – Khang