Ruby on rails Mongoid查询哈希字段与其他字段

Ruby on rails Mongoid查询哈希字段与其他字段,ruby-on-rails,ruby,mongodb,mongoid,Ruby On Rails,Ruby,Mongodb,Mongoid,文件结构- { "_id" : "b3bf7422-4993-4728-ae6f-98f35aa52a9c", "feed_user_type" : "user", "relation" : "reported_by", "notification_title" : "Thank you for submitting the report. The moderators will now review the evidence.", "no

文件结构-

{
    "_id" : "b3bf7422-4993-4728-ae6f-98f35aa52a9c",
    "feed_user_type" : "user",        
    "relation" : "reported_by",
    "notification_title" : "Thank you for submitting the report. The moderators will now review the evidence.",
    "notification_type" : {
        "email" : false,
        "feed" : false,
        "notification" : true
    },
    "updated_at" : ISODate("2016-12-01T12:14:41.269Z"),
    "created_at" : ISODate("2016-12-01T12:14:41.269Z")
}
下面的查询工作正常

Userfeed.where(:notification_type.feed => true).offset(offset).limit(size).asc(:created_at)
Userfeed.where(:feed_user_type => "user").offset(offset).limit(size).asc(:created_at)
第一个查询是查询散列中的字段,第二个查询是查询普通字段并给出正确结果的简单查询

但我将这两个查询合并在一起,根本没有得到任何结果。我尝试了以下两种语法来组合上面的查询子句

userfeeds = Userfeed.where(:notification_type.feed => true,:feed_user_type => current_user.id).offset(offset).limit(size).asc(:created_at)

userfeeds = Userfeed.where(:notification_type.feed => true).where(:feed_user_type => current_user.id).offset(offset).limit(size).asc(:created_at)
如何将哈希字段查询子句与普通字段查询子句组合

谢谢

这应该可以:

all_of(:'notification_type.feed' => true,:feed_user_type => current_user.id)

抱歉,这是打字错误,编辑了文档。您是否看到任何错误,或者您没有得到任何输出。组合查询的方式,它们作为和条件工作。所以,如果您没有得到输出,请确保您有匹配的数据。但是首先,您想查询那些通知类型为“feed true”且用户是当前用户的用户吗?您可以使用({:notification\u type.feed=>true},{:feed\u user\u type=>current\u user.id})中的任意一个这将作为或工作,您可以查看是否首先获得输出。@satishchennupati是的,我想这样做,并且我有匹配的数据。好的,我试试你的approach@satishchennupati这个#true},{:feed_user_type=>current_user.id})我得到了错误的参数错误,表示1预期2给定