【发布时间】:2015-04-25 09:22:47
【问题描述】:
我正在尝试在 Mongoose 中进行 geoNear + 文本搜索聚合查询:
landmarkSchema.aggregate(
[
{ "$geoNear": {
"near": {
"type": "Point",
"coordinates": [parseFloat(userCoord1), parseFloat(userCoord0)]
},
"distanceField": "distance",
"minDistance": 1,
"maxDistance": 5000,
"spherical": true,
"query": { "loc.type": "Point" }
} },
{ $match: { $text: { $search: sText } } },
{ $sort: { score: { $meta: "textScore" } } }
],
function(err,data) {
if (data){
res.send(data);
}
else {
console.log('no results');
res.send({err:'no results'});
}
});
但是 Mongo 没有返回任何结果。当我分别执行每个查询时,$geoNear 和 $match : $text 会返回正确的结果。我是否错误地链接了查询?
【问题讨论】:
-
来自 mongodb IRC 的一位用户说:“只有一个索引可以用于聚合”——任何人都有这种查询的最佳实践吗?
标签: node.js mongodb mongoose mongodb-query