Error when doing aggregate command with $ geoNear from MongoDB

1

I have a collection called 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 aggregate command in 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 not figure out what I'm doing wrong.

    
asked by anonymous 23.02.2018 / 18:56

1 answer

0

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

Apparently collection can not have the same attribute name, as in error:

field=location.location.coordinates

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

    
23.02.2018 / 20:06