Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4522

Make #any? not retrieve entire result set, like #exists?

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.2.0.rc1
    • Affects Version/s: 5.2.1
    • Component/s: Query
    • Labels:
      None
    • any? on has_many associations no longer retrieves the entire association from the database. This makes any? more efficient in most cases, but repeated calls to any? when the association is not loaded will query the database on every call.
    • Minor Change

      I have a simple class:

      class Article
        include Mongoid::Document
      end
      

      Here are some simple queries with the mongo query made:

      Article.criteria.any?
      => {"find"=>"articles", "filter"=>{}}
      
      Article.criteria.exists? # or empty? or blank? or present?
      => {"find"=>"articles", "filter"=>{}, "projection"=>{"_id"=>1}, "limit"=>1}
      

      I couldn't find the reason why any? is not optimized like the other methods. Is there an explanation? And can we improve this?

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            CedricBm Cedric Beaumont
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: