Supponiamo che le coordinate in basso a sinistra e in alto a destra siano rispettivamente [0, 0]
e [100, 100]
. Da MongoDB 3.2 puoi usare $slice
operatore per restituire un sottoinsieme di un array che è ciò che desideri.
db.collection.aggregate([
{ "$match": {
"loc": {
"$geoWithin": {
"$box": [
[0, 0],
[100, 100]
]
}
}}
}},
{ "$group": {
"_id": "$name",
"submitted": { "$max": "$submitted" },
"preview": { "$first": "$preview" }
"locs": { "$push": "$loc" }
}},
{ "$project": {
"locs": { "$slice": [ "$locs", 5 ] },
"preview": 1,
"submitted": 1
}},
{ "$limit": 10 }
])