【问题标题】:Mongoid query with OR and WHERE带有 OR 和 WHERE 的 Mongoid 查询
【发布时间】:2012-06-21 12:19:12
【问题描述】:

我正在构建一个 rails3 网络应用程序。 mongoid中是否有这样的查询

 db.collection.where((:status => "abc" OR :status2=>"abc") , :license=>"Active")

我不知道我的集合中存在哪些字段,status 和 status2 字段之间的一个可能存在于我的集合中,或者两者都存在。

更新 我发现我可以将 any_of 用于 OR 但它不起作用。查询是runny find,但没有结果。

 db.collection.any_of(:status=>"abc",:status2=>"abc").where(:license=>"Active") 

【问题讨论】:

  • 您尝试阅读文档了吗?
  • 是的。我发现我可以使用 any_of 但它不起作用。我的查询 db.collection.any_of(:status=>"abc",:status2=>"abc").where(:license=>"Active")
  • 您的查询有误。再次阅读文档。
  • 谢谢,找到了答案 - db.collection.any_of({:status=>"abc"},{:status2=>"abc"}).where(:license=>"积极的”)。可能是我发布这个问题有点早。

标签: nosql mongoid


【解决方案1】:

没有足够的搜索就发布了这个问题。答案是

 db.collection.any_of({:status=>"abc"},{:status2=>"abc"}).where(:license=>"Active‌​")

【讨论】:

    猜你喜欢
    • 2012-09-01
    • 1970-01-01
    • 2020-08-15
    • 2012-10-11
    • 1970-01-01
    • 2017-09-07
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多