MongoDB V: 3.6
I have an array with 6 elements, each element have 2 values: fileName
and count
I want to get all elements in the array that have a count of 0
I have tried to use this code but it only returns one element, not all the elements that match.
await User.findOne({email:email},
{ ackFiles: { $elemMatch: { count: 0 } } });
it only return this :
{ _id: 5b55d0fd9dc644051c801058,
ackFiles: [ { fileName: 'terms_of_use_vad', count: 0 } ] }
db.getCollection('').aggregate([{"$match": {"email": ""}},
{"$group" : {"_id" : {"email": "$email"}}},
{
"$project": {
"files": {
"$filter": {
"input": "$ackfiles",
"as": "file",
"cond": {
"$in": ["$$file.count", [0]]
}
}
}
}
}
])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.