-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
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])
- => #<Mongoid::Criteria
- selector: {"_id"=>
Unknown macro: {"$in"=>[BSON}
}
- options: {}
- class: TestModel
- embedded: false>
- Mongo 2.6
- Mongoid 4
- It overwrite the criteria
criteria = criteria.where(:_id.in => [id3]) - => #<Mongoid::Criteria
- selector: {"_id"=>
Unknown macro: {"$in"=>[BSON}
}
- options: {}
- class: TestModel
- 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?
- duplicates
-
MONGOID-4310 Chained $in clauses should be an intersection
- Closed