【发布时间】:2014-02-19 02:41:39
【问题描述】:
我想获取 Mongoose Model.aggregate 命令的结果并对其执行其他聚合方法。这个想法是我可以只查询一次数据库,聚合到某个点,然后对这些结果执行其他聚合方法,而无需再次重新查询数据库。 (下面的代码是 Coffeescript)
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 ...
这可能吗?
【问题讨论】:
标签: node.js mongodb mongoose aggregation-framework