Query is not executing in rails app using mongomapper

ε祈祈猫儿з 提交于 2019-12-11 06:57:03

问题


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.

I am using rails 3.1 and mongo_mapper ORM.

query details :

@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"}])


回答1:


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

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




回答2:


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



回答3:


Notice you don't need both the where and all.

You can simply write:

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


来源:https://stackoverflow.com/questions/9110385/query-is-not-executing-in-rails-app-using-mongomapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!