Mongomapper geospatial query "inside"

I am trying to execute the request "internally" using mongomapper. When I execute the command in the shell, everything works fine:

box = [[32.476750,-117.246094],[32.850173,-116.806641]]
db.locations.find({"location" : {"$within" : {"$box" : box}}})
// Bunch of results

However, when I run the same in the rails console, I get nil:

box = [[32.476750,-117.246094],[32.850173,-116.806641]]
Location.find(:location => {"$within" => {"$box" => box}})
 => nil 

If I do Location.first, I will go back, so I know that I am pointing to the correct db collection. What am I doing wrong with my mongomapper request that returns 0 results?

+1
source share
1 answer

Ah, I get that. Instead of using "find", instead, I used "where". Now I get the correct result.

+1
source

All Articles