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

Lift single-branch $or conditions to top level

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Backlog
    • Minor - P4
    • Resolution: Unresolved
    • None
    • None
    • Query
    • None

    Description

      When $or produces a single branch, the query can be simplified to contain just the branch on the top level. For example:

      irb(main):008:0> Band.or(hello:1)
      => 
      #<Mongoid::Criteria
        selector: {"$or"=>[{"hello"=>1}]}
        options:  {}
        class:    Band
        embedded: false>
       
      # equivalent to
       => 
      #<Mongoid::Criteria
        selector: {"hello"=>1}
        options:  {}
        class:    Band
        embedded: false>
      

      Note that, per https://www.mongodb.com/docs/mongoid/master/reference/queries/#logical-operations, this simplification must only be performed when the left side of .or doesn't have any conditions and right side has only one condition, i.e. it is insufficient to just check the arguments to .or.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: