收藏
回答

云数据库查询地理位置使用了geoNear后再用count查询出错,怎么解决?

代码如下

    const _ = db.command
    db.collection('point').where({
      Geo: _.geoNear({
        geometry: db.Geo.Point(117.22993839.100311),
        maxDistance5000,
      })
    }).count().then(console.log)

报错如下

VM922:1 Uncaught (in promise) thirdScriptError
errCode: -502001 database request fail | errMsg: [FailedOperation.Query] (BadValue) $geoNear, $near, and $nearSphere are not allowed in this context
Error: errCode: -502001 database request fail | errMsg: [FailedOperation.Query] (BadValue) $geoNear, $near, and $nearSphere are not allowed in this context
    at new u (http://127.0.0.1:30945/appservice/__dev__/WAService.js:2:233057)
    at Function.success (http://127.0.0.1:30945/appservice/__dev__/WAService.js:2:284582)
    at Object.success (http://127.0.0.1:30945/appservice/__dev__/WAService.js:2:126542)
    at y (http://127.0.0.1:30945/appservice/__dev__/WAService.js:2:536042)
    at v (http://127.0.0.1:30945/appservice/__dev__/WAService.js:2:536280)
    at http://127.0.0.1:30945/appservice/__dev__/WAService.js:2:537834
    at n.<anonymous> (http://127.0.0.1:30945/appservice/__dev__/asdebug.js:1:10216)
    at http://127.0.0.1:30945/appservice/__dev__/WAService.js:2:126542
    at http://127.0.0.1:30945/appservice/__dev__/WAService.js:2:109272

使用get时正常,使用count就报错



回答关注问题邀请回答
收藏

1 个回答

  • 邓坤力
    邓坤力
    2020-06-10

    count 无法和 geo 一起使用

    2020-06-10
    有用
    回复 2
    • Sam
      Sam
      2020-06-12
      为什么呢 感觉这个需求很常见啊
      2020-06-12
      回复
    • Johnsonྀൢ🌾
      Johnsonྀൢ🌾
      2020-09-09
      NND,终于找到答案了,答案却是二者无法一起使用
      2020-09-09
      回复
登录 后发表内容
问题标签