MongoDB - $ne Operator Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report MongoDB $ne or "not equals" operator is one of the comparison operators. The $ne operator selects those documents where the field value is not equal to the given value. It also includes those documents that do not contain the specified field. You can use this operator in methods like find(), update(), etc. as per your requirement. Syntax{field: {$ne: value}}MongoDB $ne Operator ExamplesIn the following examples, we are working with: Database: GeeksforGeeks Collection: employee Document: four documents that contain the details of the employees in the form of field-value pairs. Example 1 In this example, we are selecting those documents where the value of the experienceYear field is not equal to 2. Query: db.employee.find({experienceYear: {$ne: 2}}) .pretty()Output: Example 2In this example, we are selecting only those documents where the last name of the employees is not Goyal. Query: db.employee.find({"name.last": {$ne: "Goyal"}}) .pretty()Output: Example 3In this example, we are selecting those documents where the points array is not equal to the specified array. Query: db.employee.find ({points: {$ne: [2,4,6]}}).pretty()Output: Example 4In this example, we are updating the salary to 55000 of those employees whose department is not HR. Or in other words, set the value of the salary field to 55000 of those documents whose department field value is not equal to HR. Query: db.employee.update({department: {$ne: "HR}}, {$set: {salary: 55000 }})WriteResult({"nMatched" : 1, "nUpserted" :0, "Modified" :1})db.employee.find({department: {$ne: "HR"}}). pretty()Output: Key Takeaways About $ne OperatorThe $ne operator is used to specify a non-equality condition in MongoDBThe $ne operator is a comparison operator that can be used in queries with find(), update(), and other methods.It matches documents where the value of a field is not equal to the specified value.It is commonly used to filter documents based on values that are not equal to a specified threshold.MongoDB supports limited cross-BSON comparison through Type Bracketing when using the $ne operator. Comment A ankita_saini Follow 1 Improve A ankita_saini Follow 1 Improve Article Tags : MongoDB MongoDB Explore MongoDB Tutorial 7 min read IntroductionHow do Document Databases Work? 6 min read How MongoDB works ? 4 min read MongoDB Introduction 3 min read MongoDB: Getting Started 5 min read MongoDB - Working and Features 6 min read Difference between RDBMS and MongoDB 5 min read MongoDB vs MySQL 5 min read InstallationHow to Install and Configure MongoDB in Ubuntu? 5 min read How to Install MongoDB on MacOS 6 min read How to Install MongoDB on Windows? 5 min read Basics of MongoDBMongoDB - Database, Collection, and Document 6 min read MongoDB Cursor 9 min read DataTypes in MongoDB 8 min read What is ObjectId in MongoDB 5 min read What is a MongoDB Query? 10 min read MongoDB - Create Database using Mongo Shell 4 min read MongoDB | Delete Database using MongoShell 4 min read MongoDB CRUD Operations 3 min read MongoDB MethodsMongoDB - Insert() Method 6 min read MongoDB insertOne() Method - db.Collection.insertOne() 3 min read MongoDB insertMany() Method - db.Collection.insertMany() 6 min read MongoDB - Bulk.insert() Method 2 min read MongoDB - bulkWrite() Method 8 min read MongoDB - Update() Method 7 min read MongoDB - updateOne() Method 4 min read MongoDB updateMany() Method - db.Collection.updateMany() 4 min read MongoDB - Find() Method 3 min read MongoDB - FindAndModify() Method 6 min read MongoDB - FindOne() Method 3 min read MongoDB - findOneAndDelete() Method 6 min read MongoDB - db.collection.findOneAndReplace() Method 6 min read MongoDB - db.collection.findOneAndUpdate() Method 5 min read MongoDB - sort() Method 5 min read MongoDB - copyTo() Method 3 min read MongoDB Count() Method - db.Collection.count() 5 min read MongoDB - countDocuments() Method 5 min read MongoDB - Drop Collection 4 min read MongoDB Remove() Method - db.Collection.remove() 5 min read MongoDB - db.collection.deleteone() 2 min read MongoDB - Distinct() Method 3 min read MongoDB - limit() Method 4 min read MongoDB - skip() Method 4 min read MongoDB | ObjectID() Function 2 min read MongoDB - db.collection.CreateIndex() Method 7 min read createIndexes() Method in MongoDB 5 min read MongoDB - getIndexes() Method 4 min read MongoDB dropIndex() Method 5 min read MongoDB - dropIndexes() Method 3 min read Comparison OperatorsMongoDB - Comparison Query Operators 2 min read MongoDB $cmp Operator 4 min read MongoDB $gt Operator 4 min read MongoDB - $lt Operator 4 min read MongoDB - $eq Operator 4 min read MongoDB - $lte Operator 2 min read MongoDB - $gte Operator 2 min read MongoDB - $ne Operator 2 min read MongoDB $in Operator 4 min read MongoDB - $nin Operator 2 min read Logical OperatorsMongoDB - Logical Query Operators 3 min read MongoDB AND operator ( $and ) 4 min read MongoDB OR operator ( $or ) 6 min read MongoDB NOT operator ( $not ) 5 min read MongoDB NOR Operator ( $nor ) 4 min read Arithmetic OperatorsMongoDB $add Operator 4 min read MongoDB $subtract Operator 4 min read MongoDB $multiply Operator 4 min read MongoDB $divide Operator 4 min read MongoDB $abs operator 4 min read MongoDB $floor Operator 4 min read MongoDB $ceil Operator 3 min read MongoDB $mod Operator 1 min read MongoDB $sqrt Operator 2 min read MongoDB $pow Operator 4 min read MongoDB $exp Operator 3 min read MongoDB $log Operator 3 min read MongoDB $log10 Operator 3 min read MongoDB $ln Operator 5 min read Field Update OperatorsMongoDB - Field Update Operators 5 min read MongoDB - $max Operator 4 min read MongoDB - $min Operator 5 min read MongoDB - $inc Operator 5 min read MongoDB - $mul Operator 5 min read MongoDB - Rename Operator ($rename) 5 min read MongoDB - Current Date Operator ($currentDate) 2 min read MongoDB - $setOnInsert Operator 4 min read MongoDB Bitwise Update Operator 3 min read Array Expression OperatorsMongoDB - $isArray Operator 6 min read MongoDB $size Operator 5 min read MongoDB $arrayElemAt Operator 5 min read MongoDB $concatArrays Operator 4 min read MongoDB $reverseArray Operator 5 min read Like