Node.js 查询MongoDB问题
我正在尝试(未成功)查询具有以下结构的集合:Node.js 查询MongoDB问题,node.js,database,mongodb,search,nosql,Node.js,Database,Mongodb,Search,Nosql,我正在尝试(未成功)查询具有以下结构的集合: { origin : { lat : #, lng : #}, destination : { lat : #, lng #} } 使用此查询: { origin : { lat : { $gte: in.lat-1, $lte : in.lat+1}, lng : { $gte: in.lng-1, $lte : in.lng+1} }, d
{
origin : { lat : #, lng : #},
destination : { lat : #, lng #}
}
使用此查询:
{
origin : { lat : { $gte: in.lat-1, $lte : in.lat+1},
lng : { $gte: in.lng-1, $lte : in.lng+1}
},
destination : { lat : { $gte: out.lat-1, $lte : out.lat+ 1},
lng : { $gte: out.lng-1, $lte : out.lng +1}}
}
基本上,我试图找到坐标在我的输入/输出lats/lngs的某个范围内(这里是1)的文档。但是,当我通过这个查询时,它与我知道应该查询的文档不匹配。有什么提示吗?我不知道它为什么会起作用,但我将origin和destination拆分为它的两个子组件(lat和lng),并查询那些对我起作用的组件。要请求子文档,必须执行
origin.lat{$gte…}
db.collection.find({
"origin.lat": {
"$gte": 7,
"$lte": 10
},
"origin.lng": {
"$gte": 7,
"$lte": 10
},
"destination.lat": {
"$gte": 7,
"$lte": 10
},
"destination.lng": {
"$gte": 7,
"$lte": 10
}
})
试试看