与其他领域
问题描述:
文档结构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.",
"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)
+0
谢谢,这一个工作。 – user3775217
对不起,这是错字,编辑 – user3775217
是你看到的任何错误或者你没有得到任何输出它的文档。您将这些查询作为AND条件进行组合的方式。所以如果你没有得到输出,请确保你有匹配的数据。但首先你想要查询那些有通知类型feed true和用户是当前用户的人吗? –
你可以使用.any_of( {:notification_type.feed => true}, {:feed_user_type => current_user.id} )这将以或者你可以看到,如果你第一次得到输出。 –