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

'Where' appends instead of overwrites?

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • 12_01_17
    • Affects Version/s: 5.1.4
    • Component/s: None
    • None

      We have been using Mongoid 4.0.2 with Moped, and in this environment where has been behaving like this:

      class TestModel
      include Mongoid::Document
      end

      id1 = BSON::ObjectId.new
      id3 = BSON::ObjectId.new
      id2 = BSON::ObjectId.new

      criteria = TestModel.where(:_id.in => [id1, id2])

      1. => #<Mongoid::Criteria
      2. selector: {"_id"=>
        Unknown macro: {"$in"=>[BSON}

        }

      3. options: {}
      4. class: TestModel
      5. embedded: false>
      1. Mongo 2.6
      2. Mongoid 4
      3. It overwrite the criteria
        criteria = criteria.where(:_id.in => [id3])
      4. => #<Mongoid::Criteria
      5. selector: {"_id"=>
        Unknown macro: {"$in"=>[BSON}

        }

      6. options: {}
      7. class: TestModel
      8. embedded: false>

      We're in the process of upgrading to Mongo 3.x, which requires going to Mongoid 5.x (we're going to 5.1.4), and instead of the above behavior, it looks like where is appending to the criteria. Here is an example of what we see (using the same test as above):

      criteria = TestModel.where(:_id.in => [id1, id2])
      criteria
      => #<Mongoid::Criteria
      selector: {"_id"=>{"$in"=>[BSON::ObjectId('57fd1185685ad43e358b5d0a'), BSON::ObjectId('57fd1185685ad43e358b5d0b')]}}
      options: {}
      class: TestModel
      embedded: false>

      criteria = criteria.where(:_id.in => [id3])
      => #<Mongoid::Criteria
      selector: {"_id"=>{"$in"=>[BSON::ObjectId('57fd1185685ad43e358b5d0a'), BSON::ObjectId('57fd1185685ad43e358b5d0b'), BSON::ObjectId('57fd1190685ad43e358b5d0c')]}}
      options: {}
      class: TestModel
      embedded: false>

      Is this a bug? Or expected behavior?

            Assignee:
            Unassigned Unassigned
            Reporter:
            tjboring Tim Boring
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: