【发布时间】:2011-10-31 19:51:03
【问题描述】:
我需要根据 2 个属性检索一组答案。
这就是我想做的:
# where liker_ids is an array and user_id is a bson in the answer document
feed_answers=Answer.any_in(:liker_ids=>to_use,:user_id.in=>to_use).desc()map{|a|a}
我最终做了什么:
# to use
to_use=[some array of ids]
friend_answers=Answer.any_in(:liker_ids=>to_use).map{|a|a}
liked_answers=Answer.where(:user_id.in=>to_use).map{|a|a}
feed_answers=(friend_answers+ liked_answers).sort{|x,y| y.created_at<=>x.created_at}
问题是我不知道如何将 2 个查询合并为一个。我一直在尝试各种组合,但似乎没有任何效果。当然,我的组合方法效率非常低。
【问题讨论】: