我需要根據隱私從收集帖子發佈隊列。但我不知道如何得到這個。我有主要概念的畫思維導圖什麼,我努力實現:如何發佈帖子取決於隱私?
輸入:
var currentUser = "Andrey";
Events.find();
輸出:
[
{
//it's going to output, becouse I've created this post
"_id" : "1",
"createdBy" : "Andrey",
"private" : true,
"title" : "",
"text": "",
"members" : [
"Sheldon", "Mike"
]
},
{
//it's going to output, becouse this post not private
"_id" : "2",
"createdBy" : "Sheldon",
"private" : false,
"title" : "",
"members" : []
},
{
//it's going to output, becouse I'm one of members'
"_id" : "3",
"createdBy" : "Mike",
"private" : true,
"title" : "",
"text": "",
"members" : [
"Andrey"
]
},
{
//it's NOT going to output, becouse it's private post, I'm not the member or author
"_id" : "4",
"createdBy" : "Ana",
"private" : true,
"title" : "",
"text": "",
"members" : [
"Sheldon"
]
},
]
預期結果:
[
{
"_id" : "1",
"createdBy" : "Andrey",
"private" : true,
"title" : "",
"text": "",
"members" : [
"Sheldon", "Mike"
]
},
{
"_id" : "2",
"createdBy" : "Sheldon",
"private" : false,
"title" : "",
"text": "",
"members" : []
},
{
"_id" : "3",
"createdBy" : "Mike",
"private" : true,
"title" : "",
"text": "",
"members" : [
"Andrey"
]
}
]
但是這個想法可能是錯誤的,也許你有另一種方式?
Thanx,很多!我認爲這個問題只有一個決定,就是處理$和$或者語句,就像你的例子。我花了整整一天的時間進行實驗,現在我得到了預期的結果。而關於用戶ID,我也使用了IDS,這是例如。謝謝! –