Ruby / MongoDB:在Find中排除某些结果

时间:2012-11-16 04:04:36

标签: ruby mongodb

我通常使用:

@coll.find({"lang"=>@language,"description"=>@description,"location"=>@location},{:limit=>@results_needed}).to_a

但有时候我有一个“_ids”数组,我不希望被包含在结果中。有原生方式吗?我一直在用.delete_if进行攻击,但我想让数据库做尽可能多的工作。

1 个答案:

答案 0 :(得分:3)

怎么样?
@coll.find(:id.ne => array_of_ids)

@coll.find(:id => {:$ne => array_of_ids})

来自Not equals in mongo mapper