Help using near with maxDistance in a model. Mongo::OperationFailure: geo values have to be numbers:

145 views
Skip to first unread message

NickW

unread,
Apr 5, 2012, 11:05:48 AM4/5/12
to MongoMapper


I'm trying to add a model method to abstract radius searches within a
given distance and have them ordered by distance. I must be doing
something silly in my query syntax.

>> Site.nearest([-122.0,44.0],200)
>Mongo::OperationFailure: geo values have to be numbers: {$maxDistance: 200, $near: [ -122.0, 44.0 ] }


class Site
include MongoMapper::Document

key :id, Integer
key :name, String
key :location, Array
ensure_index [[:location, '2d']]


def self.nearest(center_point, range)
where(:location => {'$near' => center_point, '$maxDistance' =>
range}).all
end

end

Brian Hempel

unread,
Apr 5, 2012, 12:01:56 PM4/5/12
to mongo...@googlegroups.com
I'm guessing it's actually a data problem or index problem, your query looks correct.

See: http://www.mongodb.org/display/DOCS/Geospatial+Indexing ... 200 may be too large.

"By default, the index assumes you are indexing longitude/latitude and is thus configured for a [-180..180) value range"
"... $maxDistance : 10. The distance unit is the same as in your coordinate system, and so this query looks for points up to 10 meters away."

Brian

> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en

Jon Kern

unread,
Apr 6, 2012, 11:46:29 AM4/6/12
to mongo...@googlegroups.com
what happens if you get rid of max distance part of the query?

jon

blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA


NickW said the following on 4/5/12 11:05 AM:

Reply all
Reply to author
Forward
0 new messages