0
我想获取Mongoose Model.aggregate
命令的结果并在其上执行其他聚合方法。这个想法是我可以只查询一次数据库,聚合到某个点,然后对这些结果执行额外的聚合方法,而无需再次重新查询数据库。 (以下代码为Coffeescript)在现有的Mongoose聚合结果上执行附加聚合
firstAggregation = [
{
$geoNear: {
near:
type: "Point"
coordinates: geo
includeLocs: "geo"
distanceField: "distance"
maxDistance: distance
spherical: true
uniqueDocs: true
}
},
{
$match: { "active" : true }
}
]
secondAggregation = firstAggregation.concat [
{
$unwind: "$offers"
},
{
$group: {
_id: "$offers"
}
}
]
app.MyModel.aggregate firstAggregation, (err, results) ->
# ... do something with the first results ...
# **** apply secondAggregation here! ****
# the below doesn't work, but its what I want to achieve
results.aggregate secondAggregation, (err, secondResults) ->
# ... do something with the second results without having requeried the DB ...
这可能吗?
感谢您的信息!是的,我上面的例子是非常基本的,所以我会对数据进行一些手动操作,但我希望可以继续使用干净的聚合管道语法来处理一些棘手的问题。 –