Mudassirkhan
Mudassirkhan

Reputation: 439

geospatial query on mongo

I have the collection structure like:

{
name: "abcd",
location: {
type: "MultiPoint",
coordinates: [
[-73.57131,45.49758],[-73.57055,45.4984],[-73.57022,-73.57022],[-73.56968,45.49932],[-73.56896,45.50007],[-73.56807,45.50103],[-73.56722,45.50171]
]
}
}

I created index using

db.testCollection.createIndex( { coordinates: "2dsphere" })

Now I want to find nearby points from (lets say) [-73.56967,45.49933] out of the list location.coordinates thats present in my document.

So I queried

db.testCollection.find({ location:{ $near:{ $geometery:{ type:"Point", coordinates:[-73.56967,45.49933] }, $minDistance:0,$maxDistance:250}}})

but i got error:

Error: error: {
    "$err" : "Can't canonicalize query: BadValue $geometry is required for geo near query",
    "code" : 17287
}

CAN SOMEONE HELP ME OUT PLEASE!

Upvotes: 0

Views: 879

Answers (2)

Hlex
Hlex

Reputation: 971

  1. index name is incorrect

    db.testCollection.createIndex( { location: "2dsphere" })

  2. as @mrp answer there is an spell mistake. Use $geometry instead of $geometery.

Upvotes: 0

mrp
mrp

Reputation: 51

There is a spelling mistake. Use $geometry instead of $geometery.

Try the following query

db.testCollection.find(
    { location:{ $near:{ $geometry:{ type:"Point", coordinates:[-73.56967,45.49933] }, 
                 $minDistance:0,$maxDistance:250}}
    })

Upvotes: 1

Related Questions