为什么在MongoDB查询中使用球形时会收到错误消息

为什么在MongoDB查询中使用球形时会收到错误消息,mongodb,mongodb-query,Mongodb,Mongodb Query,我想找到[2,2.01]的最近点,我键入了下面的查询语句,但它给了我一条错误消息:geo near query中的参数无效:球面,详细信息可以在下面找到 > db.places.find() { "_id" : ObjectId("5892a41f8c4ec25d8bf6bc61"), "log" : [ 2, 2 ] } { "_id" : ObjectId("5892a4298c4ec25d8bf6bc62"), "log" : [ 4, 2 ] } { "_id" : ObjectI

我想找到[2,2.01]的最近点,我键入了下面的查询语句,但它给了我一条错误消息:geo near query中的参数无效:球面,详细信息可以在下面找到

> db.places.find()
{ "_id" : ObjectId("5892a41f8c4ec25d8bf6bc61"), "log" : [ 2, 2 ] }
{ "_id" : ObjectId("5892a4298c4ec25d8bf6bc62"), "log" : [ 4, 2 ] }
{ "_id" : ObjectId("5892a43a8c4ec25d8bf6bc63"), "log" : [ 1, 1 ] }
{ "_id" : ObjectId("5892a4448c4ec25d8bf6bc64"), "log" : [ 2, 5 ] }
{ "_id" : ObjectId("5892a44f8c4ec25d8bf6bc65"), "log" : [ -20, 23 ] }
{ "_id" : ObjectId("5892a45f8c4ec25d8bf6bc66"), "log" : [ 40.757699, -73.987632 ] }
> db.place.find( { log:
... { $near : { $geometry : 
...               { type: "Point", coordinates : [2, 2.01]},
...               spherical : true
...           }
... }})
Error: error: {
    "ok" : 0,
    "errmsg" : "invalid argument in geo near query: spherical",
    "code" : 2,
    "codeName" : "BadValue"
}

考虑使用猫鼬

 let memos = await Memo.find({})
        .where('loc')
        .near({
          center: {
            type: 'Point',
            coordinates: [parseFloat(lng), parseFloat(lat)],
            spherical: true,
            maxDistance: 2
          }
        })
        .select('img loc')
        .limit(30)

spherical
选项在
$geoNear
上,而不是在
$geometry
上Hi Sidgate,感谢您的回复,我将$geometry更改为$geoNear,但是,我再次出错,它说:errmsg:“geo-near查询中的参数无效:$geoNear”。所以我在想也许我用错了球面