使用 mongomapper 在 Rails 应用程序中未执行查询

发布于 2025-01-02 03:08:04 字数 1046 浏览 5 评论 0 原文

在我的 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"}])

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扬花落满肩 2025-01-09 03:08:04

当您使用它时,它只会创建查询,您需要通过附加来“执行”它。

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

在这里阅读更多内容: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

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

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

清君侧 2025-01-09 03:08:04
@c = Customer.where(:gender => "Male",:city => "DELHI/NCR").all
@c = Customer.where(:gender => "Male",:city => "DELHI/NCR").all
胡大本事 2025-01-09 03:08:04

请注意,您不需要同时使用 whereall

你可以简单地写:

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

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

You can simply write:

@customers = Customer.all(:gender => "Male", :city => "DELHI/NCR")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文