U kunt onderstaande aggregatie gebruiken met $objectToArray
in mongodb 3.4 en hoger
db.collection.aggregate([
{ "$addFields": {
"field": { "$objectToArray": "$$ROOT" }
}},
{ "$match": { "field.k": { "$regex": "need_" }}},
{ "$project": { "field": 0 }}
])
Geeft u output
[
{
"_id": 1,
"need_more": 1,
"need_some": "A",
"website_id": "123456789"
},
{
"_id": 2,
"need_more": 2,
"website_id": "123456789"
}
]