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

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

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Query

      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.

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

              Created:
              Updated: