Error when doing Aggregate command with Mongodb $geoNear

Asked

Viewed 34 times

1

I own a collection calling for location with the following data:

{
    _id: ObjectId("5a900f4af1b7fd855010c0cf"),
    car_id: ObjectId("5a85c26a35fdcf1098c23480"),
    location: {
        type:"Point",
        coordinates:[-54.585186,-25.447471]
    }
}

And I’m trying to make a command aggregate in the mongoshell as follows:

db.location.aggregate([{
  $geoNear: {
    near: { type: "Point", coordinates: [ -73.99279 , 40.719296 ] },
    distanceField: "dist.calculated",
    includeLocs: "dist.location",
    spherical: true,
    maxDistance: 10000
  }
}])

But I always get this error message:

assert: command failed: {
        "ok" : 0,
        "errmsg" : "geoNear command failed: { ok: 0.0, errmsg: \"error processing query: ns=taxxer.location limit=100Tree: GEONEAR  field=location.location.coordinates maxdist=10000 isNearSphere=1\nSort: {}\nProj: { $...\", code: 2, codeName: \"BadValue\" }",
        "code" : 16604,
        "codeName" : "Location16604"
} : aggregate failed

I can’t figure out what I’m doing wrong.

1 answer

0


I solved the problem by changing the name of my collection where are the location to another.

Apparently the collection cannot have the same attribute name as in the error:

field=location.location.coordinates

When changing the name to something else, for example, carlocation, the command already works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.