使用 mongomapper 在 Rails 应用程序中未执行查询
在我的 Rails 应用程序中,我正在将 mongo db 查询写入应该执行 AND 操作的集合(示例:基本上我想要来自 city=delhi 和 sex=male 的集合中的所有用户详细信息)。我被困住了在此,我指的是这个链接。 http://mongomapper.com/documentation/plugins/querying.html。即使我也遵循了以下链接 2 上的 MongoMapper OR 子句列 - Rails 3.1.rc4。但没有任何效果,我对此很陌生,我不知道这是正确的方法还是有任何方法,请帮助我解决这个问题。
我正在使用 Rails 3.1 和 mongo_mapper ORM。
查询详细信息:
@c=Customer.where(:$and => [:gender => "Male",:city => "DELHI/NCR"])
Output: #<Plucky::Query $and: [{:gender=>"Male", :city=>"DELHI/NCR"}], transformer: #<Proc:0xe6429b4@/home/vijay/.rvm/gems/ruby-1.9.2-p290/gems/mongo_mapper-0.11.0/lib/mongo_mapper/plugins/querying.rb:79 (lambda)>>
我也尝试过这个没有任何效果
@c=Customer.where(:$and => [{:gender => "Male"},{:city => "DELHI/NCR"}])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您使用它时,它只会创建查询,您需要通过附加来“执行”它。
在这里阅读更多内容:http://mongomapper.com/documentation/plugins/querying.html#criteria
as you use it it would only create the query, you will need to 'execute' it by appending .all
read more on it here: http://mongomapper.com/documentation/plugins/querying.html#criteria
请注意,您不需要同时使用
where
和all
。你可以简单地写:
Notice you don't need both the
where
andall
.You can simply write: