Casbah $ nearSphere不支持$ maxDistance

时间:2014-11-12 04:30:31

标签: mongodb scala mongodb-query casbah

我在bikes.loc字段

上有2dSphere索引

我的以下查询在mongo shell中工作正常

db.bikes.find({
fromDate: {
    $lte: ISODate("2014-10-11T00:01:00Z")
},
toDate: {
    $gte: ISODate("2014-10-12T05:05:00Z")
},
bikeType: "Road",
loc: {
    $near: {
        $geometry: {
            type: "Point",
            coordinates: [
                -121.8867076,
                37.3357192
            ]
        },
        $maxDistance: 10
    }
}
});

然而,在Cashbah中,scala $ maxDistance无法识别

("loc" $nearSphere(long, lat) $maxDistance 10)

Scala版本2.11.2

gradle org.mongodb中的Casbah依赖:casbah_2.11:2.7.3

该错误是否仍然存在?

1 个答案:

答案 0 :(得分:0)

看起来不是。但是你应该在这里使用$near运算符。这是示例test in the source distribution

  "With a $maxDistance specification" in {
    val near = "foo" $near(74.2332, -75.23452) $maxDistance 5
    near must beEqualTo(
      MongoDBObject(
        "foo" -> MongoDBObject(
          "$near" -> MongoDBList(74.2332, -75.23452),
          "$maxDistance" -> 5)))
  }
}

该列表截至2.7.3版本

因此,在查询DSL中支持此功能,但正如测试条件中所述,即使

MongoDBObject(
    "loc" -> MongoDBObject(
        "$nearSphere" -> MongoDBObject(
            "type" -> "Point",
            "coordinates" -> MongoDBList(-121.8867076,37.3357192)
        ),
        "$maxDistance" -> 10 ))