को सीमित करने के लिए कैसे करें मैं समेकन पाइपलाइन के साथ समूह फ़ंक्शन में धक्का तत्वों की मात्रा को सीमित करने में सक्षम नहीं हूं। क्या यह संभव है? छोटा सा उदाहरण:मोंगोड एग्रीगेशन पाइपलाइन समूह पुश
डाटा:
[
{
"submitted": date,
"loc": {
"lng": 13.739251,
"lat": 51.049893
},
"name": "first",
"preview": "my first"
},
{
"submitted": date,
"loc": {
"lng": 13.639241,
"lat": 51.149883
},
"name": "second",
"preview": "my second"
},
{
"submitted": date,
"loc": {
"lng": 13.715422,
"lat": 51.056384
},
"name": "nearpoint2",
"preview": "my nearpoint2"
}
]
यहाँ मेरी एकत्रीकरण पाइप लाइन है:
var pipeline = [{
//I want to limit the data to a certain area
$match: {
loc: {
$geoWithin: {
$box: [
[locBottomLeft.lng, locBottomLeft.lat],
[locUpperRight.lng, locUpperRight.lat]
]
}
}
}
},
// I just want to get the latest entries
{
$sort: {
submitted: -1
}
},
// I group by name
{
$group: {
_id: "$name",
< --get name
submitted: {
$max: "$submitted"
},
< --get the latest date
locs: {
$push: "$loc"
},
< --push every loc into an array THIS SHOULD BE LIMITED TO AN AMOUNT 5 or 10
preview: {
$first: "$preview"
}
}
},
//Limit the query to at least 10 entries.
{
$limit: 10
}
];
मैं 10
या किसी अन्य आकार के locs
सरणी कैसे सीमित कर सकते हैं? मैंने $each
और $slice
के साथ कुछ करने की कोशिश की लेकिन ऐसा लगता है कि यह काम नहीं कर रहा है।
इस सीधे धक्का पर करने के लिए कोई रास्ता नहीं है? – Nickpick
इस समय धक्का पर ऐसा करना संभव नहीं है @ निकपिक – styvane