क्योंकि आपको release
की आवश्यकता नहीं है "GB" क्षेत्र के तत्वों के अलावा, आप इसे aggregate
. के साथ कर सकते हैं इस तरह:
db.products.aggregate(
// Filter the docs to just those containing the 'GB' region
{ $match: {'release.region': 'GB'}},
// Duplicate the docs, one per release element
{ $unwind: '$release'},
// Filter the resulting docs to just include the ones from the 'GB' region
{ $match: {'release.region': 'GB'}},
// Sort by release date
{ $sort: {'release.date': 1}})
आउटपुट:
{
"result": [
{
"_id": "baz",
"release": {
"region": "GB",
"date": ISODate("20110501T00:00:00Z")
}
},
{
"_id": "foo",
"release": {
"region": "GB",
"date": ISODate("20120301T00:00:00Z")
}
},
{
"_id": "bar",
"release": {
"region": "GB",
"date": ISODate("20120501T00:00:00Z")
}
}
],
"ok": 1
}