ruby /MongoDB : Exclude certain results in Find

标签 ruby mongodb

我通常使用:

@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})

来自 Not equals in mongo mapper .

关于 ruby /MongoDB : Exclude certain results in Find,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410224/

相关文章:

mongodb - MongoDB中的 `$or`和 `$in`查询如何排序?

node.js - 如何更新 mongoDB 或 Mongoose 中的嵌套数组值

php - MongoDB 更新 : how to check if an update succeeds or fails?

ruby:如果项目的某些键相同,如何从数组中获取第一个散列项?

java - 为什么 App Engine 上的 JRuby 应用程序需要很长时间才能启动(与 Python 应用程序相比)?

javascript - 在浏览器中运行代码

mongodb - 在scala中将dataframe转换为json

node.js - 蒙戈错误: query selector must be an object

ruby-on-rails - Rails 协会 : One way associations

ruby - 我应该以多用户身份安装 RVM 吗?