Multiple $near in mongo 2.6.4 does not work Multiple $near in mongo 2.6.4 does not work json json

Multiple $near in mongo 2.6.4 does not work


Mongo DB accepts only one NEAR. And if there is a NEAR, it must be either the root or the rootmust be an AND and its child must be a NEAR. See https://github.com/mongodb/mongo/blob/master/src/mongo/db/query/canonical_query.cpp#L364

If you need that $or operation with two $near, try to make two queries and integrate the results from them.


An example with $or

db.Truck.find({    "DestinationLocation": {        "$or":[{          "$near": {              "$geometry": {                  "type": "Point",                  "coordinates": [-117.256875, 41.856405]              },              "$maxDistance": 100000.0            }        },{        "$near": {            "$geometry": {                "type": "Point",                "coordinates": [-112.256875, 40.856405]            },            "$maxDistance": 100000.0          }        }]    }})