私はこのスキーマを持っています
{
cc: [
{ user_id: "1", hasSeen:true}
,{ user_id: "2", hasSeen:false}
,{ user_id: "3", hasSeen:false}
]
,conversation: [{
user_id: "1",
text: "message by 1, to 2and3"
}]
}
,{
cc: [
{ user_id: "1", hasSeen:true}
,{ user_id: "2", hasSeen:false}
,{ user_id: "3", hasSeen:false}
,{ user_id: "4", hasSeen:false}
]
,conversation: [{
user_id: "1",
text: "message by 1, to 2,3and4"
}]
}
これが「受信トレイ」データベースの設定方法です。ユーザー「1」がいる会話を見つけるには、次のクエリを使用します。
find({ cc:{$elemMatch:{ user_id:"1"}} })
うまく機能しますが、両方の結果が返されます。
ここで、ユーザー 1、2、3のみを持つ要素を見つけたいと思います。このクエリを使用すると
find({ cc:{$elemMatch:{ user_id:"1", user_id:"2", user_id:"3" }} })
それは私に2番目の要素も返します。魔女にはユーザー4も含まれています(そして私はそれを取得したくありません)。
つまり、最後のクエリは (sql) "or" 演算子として機能し、"and" 演算子を使用する必要があります。
何か案が?