I have documents with a schema such as follows:
{
\"user_id\": 123,
\"services\":[
{\"name\": \"test\",
\"data\": ...
},
You need to run $unwind to get single document from services
and $replaceRoot to promote it to root level:
db.guilds.aggregate([
{
$match: { user_id: 123, "services.name": "test" }
},
{
$unwind: "$services"
},
{
$match: { "services.name": "test" }
},
{
$replaceRoot: { newRoot: "$services" }
}
])