首页 > 解决方案 > 如何搜索不等于指定值的值?

问题描述

我正在使用 MongoDB,我需要一个查询来检查一个值不是某个值,我知道如何搜索这样的值:

db.getCollection('ships').find({"name": "MY BOAT"})

所以假设我需要一个查询来查找名称不是“MY BOAT”的条目

我已经检查了$NOT运算符https://docs.mongodb.com/manual/reference/operator/query/not/

但不明白如何应用它。

标签: mongodb

解决方案


db.getCollection('ships').find( { name: { $ne: "MY BOAT" } } )

https://docs.mongodb.com/manual/reference/operator/query/ne/

follow the above url for more information

推荐阅读