Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot chain geo_near #13

Open
pdelanauze opened this issue Dec 1, 2011 · 5 comments
Open

Cannot chain geo_near #13

pdelanauze opened this issue Dec 1, 2011 · 5 comments

Comments

@pdelanauze
Copy link

Can we not chain the geo_near query ?

Say we have a scope

scope :enabled, where(:enabled => true)

This chain would work:

def look_for_enabled_close_to
  self.enabled.geo_near([1.0, 1.0], :max_distance => 5, :unit => :km, :spherical => true)
end

This would not, throws a NoMethodError: undefined method `scoped' for #Mongoid::Spacial::GeoNearResults:0x00000105455258

def look_for_enabled_close_to
  self.geo_near([1.0, 1.0], :max_distance => 5, :unit => :km, :spherical => true).enabled
end

Also, wrapping geo_near in a scope results in the same exception being thrown...
e.g.

scope :geo_near_plus_plus, lambda {|coords, rad| geo_near(coords, :max_distance => rad)}

Here's the stack trace

NoMethodError: undefined method `scoped' for #<Mongoid::Spacial::GeoNearResults:0x00000105455258>
    from /Users/pat/.rvm/gems/ruby-1.9.2-p0/gems/mongoid-2.3.4/lib/mongoid/extensions/proc/scoping.rb:20:in `scoped'
    from (eval):3:in `geo_near_plus_plus'
    from /Users/pat/.rvm/gems/ruby-1.9.2-p0/gems/mongoid-2.3.4/lib/mongoid/criteria.rb:379:in `block in method_missing'
    from /Users/pat/.rvm/gems/ruby-1.9.2-p0/gems/mongoid-2.3.4/lib/mongoid/named_scope.rb:120:in `with_scope'
    from /Users/pat/.rvm/gems/ruby-1.9.2-p0/gems/mongoid-2.3.4/lib/mongoid/criteria.rb:378:in `method_missing'
@cblavier
Copy link

+1, would be really great if geo_near queries could be chained with scopes

@demersus
Copy link

This just threw a wrench in one of my search models... +1 Please implement this feature

kristianmandrup referenced this issue in kristianmandrup/mongoid_geospatial Nov 6, 2012
@TangMonk
Copy link

TangMonk commented Apr 2, 2015

same issue

@ryanong
Copy link
Owner

ryanong commented Apr 2, 2015

geo near queries cannot be chained in mongodb

@TangMonk
Copy link

TangMonk commented Apr 2, 2015

I am try to using Postgres with Postgis, It seems better than mongodb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants