【发布时间】:2020-05-29 16:10:35
【问题描述】:
我一直在使用 $near 运算符进行简单搜索,但最近更改了我的数据,因此 2dsphere 位置索引现在位于嵌套字段 properties.location 中,而不仅仅是 location。我正在使用 Node JS mongo 驱动程序,当索引没有嵌套在 properties 对象中时,搜索工作正常,使用以下查询,但现在什么都不返回:
以前的工作查询:
dbObject.collection("scrapedTimes").find({
location: {
$near: {
$geometry: {
type: "Point" ,
coordinates: [lngBound, latBound]
},
$minDistance: 0,
$maxDistance: 100000
}
}
})
当前不返回任何内容的查询:
dbObject.collection("scrapedTimes").find({
"properties.location": {
$near: {
$geometry: {
type: "Point" ,
coordinates: [lngBound, latBound]
},
$minDistance: 0,
$maxDistance: 100000
}
}
})
我在 Mongo Compass 中执行了同样的嵌套查询,它似乎工作正常,所以我认为这可能是 Node JS 驱动程序的问题?我对 Mongo 很陌生,所以我可能在这里遗漏了一些明显的东西,但我无法让 Node 返回任何结果......
感谢您的宝贵时间和建议,
乔什
【问题讨论】:
-
您是否尝试在查询中将
$near更改为$nearSphere...保持其他所有内容不变... -
太棒了!,请为我的回答点赞……:/
标签: node.js mongodb mongoose geojson