逻辑“与”的问题在 mongomapper 中查询?
我在 Rails 应用程序中使用 mongo db 作为模型,当我执行时,
Model.where(:$or => [{:field1 => true}, {:field2 => true}])
产生勇敢的查询
#<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)>>
执行 OR 操作并获取正确的结果,即 field1 或 field2 为 true 但
Model.where(:$and => [{:field1 => true}, {:field2 => true}])
产生勇敢的查询
#<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)>>
不执行 AND 操作,而是它抛出错误
Mongo::OperationFailure 异常:$and 表达式必须是非空 数组
详细信息
Rails 版本:3.1, 蒙戈版本:2.0.0, mongo_mapper gem 版本:0.9.2
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要升级 MongoMapper。
$and
支持在 plucky 0.4.x 中添加,MongoMapper 从 0.10.1 版本开始使用。此提交添加了对 plucky 的
$and
支持,并且是勇敢的 0.4.2 及更高版本。此提交更新了 MongoMapper 以使用 plucky 0.4.x,并且是 MM 0.10.1 的一部分更大。
You will need to upgrade MongoMapper.
$and
support was added in plucky 0.4.x, which MongoMapper uses as of version 0.10.1.This commit added
$and
support 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.