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

Merge strategies produce wrong queries when previous conditions weren't added to top level

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Backlog
    • Major - P3
    • Resolution: Unresolved
    • None
    • None
    • Query

    Description

      Taking the merge strategy example in https://www.mongodb.com/docs/mongoid/master/reference/queries/#merge-strategies and expanding it to operate over a criteria that places the conditions under $and, we get incorrect results:

      irb(main):005:0> Band.where(name: {:$in => 42}).in(name: ['a']).override.in(name: ['b'])
      => 
      #<Mongoid::Criteria
        selector: {"name"=>{"$in"=>["b"]}, "$and"=>[{"name"=>{"$in"=>["a"]}}]}
        options:  {}
        class:    Band
        embedded: false>
      

      You might expect that `b` would replace `a`, instead the earlier `42` got replaced by `b` and `a` is still there.

      If we are not able to come up with a solution, we should at least document this issue.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: