node.js - 在 MongoDB 中查找不符合条件的记录

标签 node.js mongodb

<分区>

我需要将条件传递给 find 方法。但是使用比较运算符 !=。在 MongoDB 中有可能吗?我在 docs 中看到ANDOR<> 等运算符,但否定运算符。您是否知道如何获取所有记录,即 recordType 不等于 Message

collection.find({'recordType' : 'Message'}).toArray(function(err, results) {
    // <-- need NOT EQUAL OPERATOR
    });

最佳答案

$ne 是解决方案。

Syntax: {field: {$ne: value} }

$ne selects the documents where the value of the field is not equal (i.e. !=) to the specified value. This includes documents that do not contain the field.

collection.find({'recordType' : {'$ne' : 'Message'}}).toArray(function(err, results) 
{
    console.log(results);
});

引用doc了解如何使用它。

关于node.js - 在 MongoDB 中查找不符合条件的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37589047/

相关文章:

node.js - Auth0 和 React 的 CORS 问题

node.js - Mocha 测试用例不等待完成

javascript - 如何在Mongodb中使用条件语句进行排序

python - 如何在 mongoengine 中迭代数据库中的集合?

mongodb - 无法启动mongod : version 'libssl.so.10' not found

node.js - Electron Node.js Node 本地存储 osx mkdir 权限被拒绝

javascript - Node、Express、Angular 路由错误

node.js - 我应该构建一个还是两个 mongodb 模型?

无法动态链接到MongoDB c驱动库

mongodb - 在俄语的 mongodb 中进行全文搜索