Reputation: 4803
Document structure -
{
"_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")
}
Following queries works fine
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)
First query is querying the field in the hash and second one is simple query querying a normal field and gives proper results.
But i combine both the queries i don't get any results at all. I tried following two syntax for combining the above query clause
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)
How can i combine a hash field query clause with normal field query clause?
Thanks
Upvotes: 1
Views: 143
Reputation: 694
This should work:
all_of(:'notification_type.feed' => true,:feed_user_type => current_user.id)
Upvotes: 1