我通常使用:
@coll.find({"lang"=>@language,"description"=>@description,"location"=>@location},{:limit=>@results_needed}).to_a
但有时我有一个“_ids”数组,我不想包含在结果中。有没有本地方法可以做到这一点?我一直在使用 .delete_if
进行破解,但我希望让数据库尽可能多地完成工作。
最佳答案
怎么样
@coll.find(:id.ne => array_of_ids)
或
@coll.find(:id => {:$ne => array_of_ids})
关于 ruby /MongoDB : Exclude certain results in Find,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410224/