试图过滤掉任何对象?在朋友数组中?不匹配字段“friends.username”与“one@one.com”的值
final userDoc = await store.find({
'_id': ObjectId.fromHexString(authDetails.subject),
'friends.username': 'one@one.com',
'\$filter': {'friends.username': 'one@one.com'}
}).forEach((element) {
print(element);
});
我知道这是可能的,因为我可以使用
Object newReceived = {
'username': myUsername,
'timestamp': addedTime,
};
//add your name to their friend request received list
await store.updateOne({
'_id': theirId
}, {
'\$push': {'friendRequestReceived': newReceived}
});
mongodb数据库结构如下:
{
"_id" : ObjectId("60b2faa2de1f7691268bf907"),
"email" : "nine5@one.com",
"emailverified" : false,
"username" : "nine5@one.com",
"displayName" : "complete n00b",
"dob" : "",
"points" : 0,
"attended" : 0,
"hosted" : 0,
"friends" : [
{
"username" : "one@one.com",
"timestamp" : "2021-05-29 19:38:58.758325"
},
{
"username" : "nine4@one.com",
"timestamp" : "2021-05-29 19:39:54.915636"
}
]
}
我只想获取与“_id”关联的“朋友”数组下具有用户名“one@one.com”的任何文档:ObjectId(“60b2faa2de1f7691268bf907”)。并过滤掉任何不这样做的用户名,我希望最终使用此结构仅返回来自某个用户的消息,该用户在名为“_id”的消息数组下找到:ObjectId(“60b2faa2de1f7691268bf907”)。谢谢