MongoDB 查找匹配坐标比较的文档

MongoDB find document matching a coordinate comparison

我目前正在为一个 class 项目开发 mongoDB 数据库。但是,我对此很陌生。 我必须找到纬度大于特定值的所有文档:39。经度值可以是任何值。 请在下面找到一个文档的示例,显示数据库的全局结构。

Example

查看MongoDB的文档,我有两个提示:

有人可以帮助我提高自己吗?

此致,

我认为你的问题是你在数组的第一个位置寻找大于 39 的值。你的例子中的这些值都是负数,所以没有人大于 39.

如果您使用 $lt 执行相同的查询,您将获得结果。示例 here.

此外,要查找值 $gt: 39,您必须找到数组中的第二个位置:

db.collection.find({
  "end station location.coordinates.1": {
    "$gt": 39
  }
})

示例here

此外,如果您想获取几乎存在于一个字段中的值 end station locationstart station location,您需要像这样的 $or 运算符:

db.collection.find({
  "$or": [
    {
      "end station location.coordinates.1": {
        "$gt": 39
      }
    },
    {
      "start station location.coordinates.1": {
        "$gt": 39
      }
    }
  ]
})

示例here

记住,你想按第二个位置搜索数组,所以你必须使用 coordinates.1.