本文介绍了查询未使用mongomapper在Rails应用中执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails应用程序中,我正在将mongo db查询写入应该执行AND操作的集合中.(示例:基本上,我希望收集来自其中city = delhi和gender = male的集合中的所有用户详细信息).我陷入其中,我指的是这个链接. http://mongomapper.com/documentation/plugins/querying.html .即使我也遵循以下链接 MongoMapper OR子句在2列-Rails 3.1.rc4 .但是什么都没有用,我是新手,我不知道这是正确的方法,还是有任何方法,请帮我解决这个问题.

In my rails application i am writing mongo db query to collections where it should perform AND operation (Example: Basically i want all the user details from collection where city=delhi and gender=male).I am stuck in this , I am referring to this link . http://mongomapper.com/documentation/plugins/querying.html. Even i have followed the below links MongoMapper OR clause on 2 columns - Rails 3.1.rc4. But nothing is working, I am new to this i dont know is this correct approach or else is there any methods, kindly help me out in this.

我正在使用rails 3.1和mongo_mapper ORM.

I am using rails 3.1 and 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)>>

我已经尝试过了,也没有任何作用

I have tried this also nothing is working

@c=Customer.where(:$and => [{:gender => "Male"},{:city => "DELHI/NCR"}])

推荐答案

使用它只会创建查询,您需要通过附加.all

as you use it it would only create the query, you will need to 'execute' it by appending .all

@customers = Customer.where(:gender => "Male", :city => "DELHI/NCR").all

在此处了解更多信息: http://mongomapper.com/documentation/plugins/querying.html#criteria

read more on it here: http://mongomapper.com/documentation/plugins/querying.html#criteria

这篇关于查询未使用mongomapper在Rails应用中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 18:55