在MongoDB中查找不符合联系的logging
我需要通过一个条件来find
方法。 但是用比较运算符!=
。 在MongoDB中可能吗? 我在文档运算符中看到像AND
, OR
, <
; >
,但是否定运算符。 你有任何想法如何获取所有的logging,该recordType
不等于Message
?
collection.find({'recordType' : 'Message'}).toArray(function(err, results) { // <-- need NOT EQUAL OPERATOR });
$ne
是解决scheme。
语法:
{field: {$ne: value} }
$ne
select字段值not equal (ie !=)
到指定值的文档。 这包括不包含该字段的文档。
collection.find({'recordType' : {'$ne' : 'Message'}}).toArray(function(err, results) { console.log(results); });
请参阅文档以了解如何使用它。