I am using mongo db for a model in my rails application, and when I execute
Model.where(:$or => [{:field1 => true}, {:field2 => true}])
produces plucky query
#<Plucky::Query $or: [{:field1=>true}, {:field2=>true}], transformer: #<Proc:0xa4b1c5c@/home/x/.rvm/gems/ruby-1.9.2-p290@app/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:79 (lambda)>>
performs OR operation and fetches the correct results, ie, field1 or field2 is true but
Model.where(:$and => [{:field1 => true}, {:field2 => true}])
produces plucky query
#<Plucky::Query $and: {"$in"=>[{:field1=>true}, {:field2=>true}]}, transformer: #<Proc:0xa435120@/home/x/.rvm/gems/ruby-1.9.2-p290@app/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:79 (lambda)>>
doesn’t perform the AND operation, instead it throws error
Mongo::OperationFailure Exception: $and expression must be a nonempty
array
DETAILS
Rails version: 3.1,
Mongo version: 2.0.0,
mongo_mapper gem version: 0.9.2
You will need to upgrade MongoMapper.
$andsupport was added in plucky 0.4.x, which MongoMapper uses as of version 0.10.1.This commit added
$andsupport to plucky and is part of plucky 0.4.2 and greater.This commit updated MongoMapper to use plucky 0.4.x and is part of MM 0.10.1 and greater.