【问题标题】:Mongodb find near maxdistanceMongodb在maxdistance附近找到
【发布时间】:2014-11-06 09:49:06
【问题描述】:

我在 mongodb 中触发以下查询

db.acollection.find({
    "field.location": {
        "$near": [19.0723058, 73.00067739999997]
    }, 
    $maxDistance : 100000
}).count()

并得到以下错误 -

uncaught exception: count failed: {
    "shards" : {

    },
    "cause" : {
        "errmsg" : "exception: unknown top level operator: $maxDistance",
        "code" : 2,
        "ok" : 0
    },
    "code" : 2,
    "ok" : 0,
    "errmsg" : "failed on : Shard ShardA"
}

【问题讨论】:

    标签: mongodb geolocation mongodb-query


    【解决方案1】:

    你做错了。 $maxDistance 参数是 $near 运算符的“子”:

    db.acollection.find({
        "field.location": {
            "$near": [19.0723058, 73.00067739999997],
            "$maxDistance": 100000
        }
    }).count()
    

    必须在同一个表达式内。

    在制作新应用程序时还要查看 GeoJSON。这是您将来应该存储的方式。

    【讨论】:

      猜你喜欢
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 2019-10-30
      • 1970-01-01
      • 2021-11-07
      相关资源
      最近更新 更多