Casbah $nearSphere dont support $maxDistance

85 views Asked by At

I have 2dSphere index on bikes.loc field

My following query works fine in 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
    }
}
});

However in cashbah for scala $maxDistance is not recognized

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

Scala Version 2.11.2

Casbah dependency in gradle org.mongodb:casbah_2.11:2.7.3

Is the bug still open?

1

There are 1 answers

0
Neil Lunn On BEST ANSWER

It would appear not. But you should be using the $near operator here instead. This is the example 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)))
  }
}

That listing is taken as of the 2.7.3 release

So this is supported in the query DSL, but as noted in the test conditions, even if the

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