【发布时间】:2014-07-19 11:03:58
【问题描述】:
考虑以下几点:
db.stores.aggregate(
{ $project: {
_id: 0,
in_radius: {
$cond: {
if: <geoWithinExpression>,
then: 1,
else: 0
}
}
}
})
geoWithinExpression 实际上是:
$match: {
location: {
$geoWithin: {
$center: [[lat, lon], radius]
}
}
}
我这样做是为了在结果集上使用 $group 来计算该半径内的商店数量。 (我使用 $project 是因为我想做更多像这样的自定义列并一次性返回它们)。
这可能吗?
【问题讨论】:
-
检查这里可能对你有帮助,类似的问题stackoverflow.com/questions/13840720/…
标签: mongodb aggregation-framework