Myślę, że chciałeś to:
print db.dvds.aggregate([
{"$unwind": "$episodes"}, # One document per episode
{"$match": {"episodes.title": "Episode 1"} }, # Selects (filters)
{"$group": {"_id": "$_id", # Put documents together again
"episodes": {"$push": "$episodes"},
"title": {"$first": "$title"} # Just take any title
}
},
])["result"]
Dane wyjściowe (oprócz spacji) to:
[ { u'episodes': [ { u'title': u'Episode 1',
u'desc': u'...'
}
],
u'_id': ObjectId('51542645a0c6dc4da77a65b6'),
u'title': u'The Hitchhikers Guide to the Galaxy'
}
]
Jeśli chcesz pozbyć się u"_id"
, dołącz potok z:
{"$project": {"_id": 0,
"episodes": "$episodes",
"title": "$title"}
}