我想从 MongoDB 的嵌入式文档中找到一个元素。这是我在 MongoDB 中收集的用户文档:-
[
{
"userId":"001",
"userName":"abc"
"subscriptionDetails" : [
{
"planId" : "1",
"isExpired" : false,
"current" : true,
"timeStamp" : 1592570927981,
},
{
"planId" : "2",
"isExpired" : false,
"current" : true,
"timeStamp" : 1592570927909,
},
{
"planId" : "3",
"isExpired" : false,
"current" : false,
"timeStamp" : 1592570978,
}
]
},
{
"userId":"002",
"userName":"abc"
"subscriptionDetails" : [
{
"planId" : "1",
"isExpired" : false,
"current" : true,
"timeStamp" : 1592570927981,
}
]
}
]
我的 nodejs 函数通过 nodejs 本机驱动程序从嵌入式文档中查找单个元素:-
var Plan=await db.collection("user").findOne(
{
userId:001,
'subscriptionDetails.current':false,
'subscriptionDetails.isExpired':false
},
{
'projection':{ "_id": 0,'subscriptionDetails.$':1 }
}
)
console.log(plan)
但是这个函数的响应是:-
{
subscriptionDetails:
[ {
"planId" : "1",
"isExpired" : false,
"current" : true,
"timeStamp" : 1592570927981,
}
]
}
但预期的输出是: -
{
subscriptionDetails:
[ {
"planId" : "3",
"isExpired" : false,
"current" : false,
"timeStamp" : 1592570978,
}
]
}
我该如何解决这个问题?