Perché non hai bisogno del release
elementi oltre a quelli della regione "GB", puoi farlo con aggregate
così:
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}})
uscita:
{
"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
}