I\'m using javascript and the mongoose module. I have an object like this
my_object = {
ShopName: String,
employees: [String],
info: {
NameEm
You can utilize the $objectToArray (mongoDB 3.4.4 and up), $filter and $project
and get something like this:
db.collection.aggregate([
{
$project: {
obj: {
$objectToArray: "$info"
}
}
},
{
$project: {
_id: 0,
obj: {
$filter: {
input: "$obj",
as: "item",
cond: {
$eq: [
"$$item.v.city",
"NY"
]
}
}
}
}
},
{
$project: {
info: {
$arrayToObject: "$obj"
}
}
},
])
You can see it working here
The idea is to break the object to array, filter it and then convert that array back to object.
I filtered on city
but I am sure you get the idea.