I have a basic geospatial query that works well in MongoDB. It seems like it would be easy to apply $ so as not to get the add-on ... but this does not work for me. Simple user error? Or can MongoDB conceptually not handle this request? I could not find such a limitation in the documentation.
Work request (correctly finds 2 cities within a radius of 10 miles from the center):
db.customers.find({ "location" : { $within : { $center : [[-117.15,32.72],0.15] } } })
Attempt to request a supplement (the desired result is 1 city that is not within 10 miles):
db.customers.find({ "location" : { $not : { $within : { $center : [[-117.15,32.72],0.15] } } } }) error: { "$err" : "missing geo field (location) in : {location: { $not: { $within: { $center: [ [ -117.15, 32.72 ], 0.15 ] } } } }", "code" : 13042 }
For those who want to copy / paste a query to see the error, here is a tiny bit of sample data:
db.customers.ensureIndex( { "location" : "2d" } ) db.customers.save({"city":"La Mesa","state":"CA","location":[ -117.02,32.76 ]}) db.customers.save({"city":"Chula Vista","state":"CA","location":[ -117.08,32.63 ]}) db.customers.save({"city":"Mexico City","state":"Mexico","location":[-99.133244,19.4326]})
(I use MongoDB 1.8.2 in case that matters.)
mdahlman
source share