I have a mongo documnet of
{
"locationId": "5f2084f756dc2428e96fcda4",
"information": [{
"category": ["5e5150c6c52a3904b74d6ff7"],
"date": {
"$date": {
"$numberLong": "1601407317343"
}
},
"private": true
}, {
"category": ["5e5150c6c52a3904b74d6ff7"],
"date": {
"$date": {
"$numberLong": "1601407317343"
}
},
"private": false
},
}],
}
So far, what I have is to query the nested array.
const f = await info.aggregate([
{
$match: {
$and: [
{'locationId': '5f2084f756dc2428e96fcda4'},
{'information.private': true}
]
},
},
]);
I am trying to query information.private = true. However, I receive both 'private: false' and 'private: true'. The outcome is
[
{
"_id": ObjectId("5a934e000102030405000000"),
"information": [
{
"category": [
"5e5150c6c52a3904b74d6ff7"
],
"date": ISODate("2020-09-29T19:21:57.343Z"),
"private": true
},
{
"category": [
"5e5150c6c52a3904b74d6ff7"
],
"date": ISODate("2020-09-29T19:21:57.343Z"),
"private": false
}
],
"locationId": "5f2084f756dc2428e96fcda4"
}
]
I also tried with elemMatch and returns the same results. I'd looked up multiple answers on Stackoverflow but the dot notation and elemMatch do not work in this case. I know that I have done something wrong but I can't figure it out.