Pergunta

I'm trying to fetch records within a specific radius in km/miles.

mongodb 2d index:

db.collection.ensureIndex({locaction:"2d"})

a record in the collection has the indexed key:

"location" : { "longitude" : 34.791592164168, "latitude" : 32.0516908 0405 }

Calling collection's getIndexes() from shell gives me this:

       ...{
           "v" : 1,
           "key" : {
                   "location" : "2d"
           },
           "ns" : "events.events",
           "name" : "location_2d"
   }...

despite all the above, trying to fetch records with this command fails:

> db.events.find({location:{ $near :{ longitude:34,latitude:32},$maxDistance:10 / 3963.192}})

anyone can point out what prevent this from working?

Foi útil?

Solução

AFAIK, $near takes an array of the two target values, so you can try giving your values in array: -

db.events.find({location:{ $near : [34, 32],$maxDistance:10 / 3963.192}})
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top