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. Create Quiz Comment A ankita_saini Follow 1 Improve A ankita_saini Follow 1 Improve Article Tags : MongoDB MongoDB Explore IntroductionHow do Document Databases Work?6 min readHow MongoDB works ?4 min readMongoDB Introduction3 min readMongoDB: Getting Started5 min readMongoDB - Working and Features6 min readDifference between RDBMS and MongoDB5 min readMongoDB vs MySQL5 min readInstallationHow to Install and Configure MongoDB in Ubuntu?5 min readHow to Install MongoDB on MacOS6 min readHow to Install MongoDB on Windows?5 min readBasics of MongoDBMongoDB - Database, Collection, and Document6 min readMongoDB Cursor9 min readDataTypes in MongoDB8 min readWhat is ObjectId in MongoDB5 min readWhat is a MongoDB Query?10 min readMongoDB - Create Database using Mongo Shell4 min readMongoDB | Delete Database using MongoShell4 min readMongoDB CRUD Operations3 min readMongoDB MethodsMongoDB - Insert() Method6 min readMongoDB insertOne() Method - db.Collection.insertOne()3 min readMongoDB insertMany() Method - db.Collection.insertMany()6 min readMongoDB - Bulk.insert() Method2 min readMongoDB - bulkWrite() Method8 min readMongoDB - Update() Method7 min readMongoDB - updateOne() Method4 min readMongoDB updateMany() Method - db.Collection.updateMany()4 min readMongoDB - Find() Method3 min readMongoDB - FindAndModify() Method6 min readMongoDB - FindOne() Method3 min readMongoDB - findOneAndDelete() Method6 min readMongoDB - db.collection.findOneAndReplace() Method6 min readMongoDB - db.collection.findOneAndUpdate() Method5 min readMongoDB - sort() Method5 min readMongoDB - copyTo() Method3 min readMongoDB Count() Method - db.Collection.count()5 min readMongoDB - countDocuments() Method5 min readMongoDB - Drop Collection4 min readMongoDB Remove() Method - db.Collection.remove()5 min readMongoDB - db.collection.deleteone()2 min readMongoDB - Distinct() Method3 min readMongoDB - limit() Method4 min readMongoDB - skip() Method4 min readMongoDB | ObjectID() Function2 min readMongoDB - db.collection.CreateIndex() Method7 min readcreateIndexes() Method in MongoDB5 min readMongoDB - getIndexes() Method4 min readMongoDB dropIndex() Method5 min readMongoDB - dropIndexes() Method3 min readComparison OperatorsMongoDB - Comparison Query Operators2 min readMongoDB $cmp Operator4 min readMongoDB $gt Operator4 min readMongoDB - $lt Operator4 min readMongoDB - $eq Operator4 min readMongoDB - $lte Operator2 min readMongoDB - $gte Operator2 min readMongoDB - $ne Operator2 min readMongoDB $in Operator4 min readMongoDB - $nin Operator2 min readLogical OperatorsMongoDB - Logical Query Operators3 min readMongoDB AND operator ( $and )4 min readMongoDB OR operator ( $or )6 min readMongoDB NOT operator ( $not )5 min readMongoDB NOR Operator ( $nor )4 min readArithmetic OperatorsMongoDB $add Operator4 min readMongoDB $subtract Operator4 min readMongoDB $multiply Operator4 min readMongoDB $divide Operator4 min readMongoDB $abs operator4 min readMongoDB $floor Operator4 min readMongoDB $ceil Operator3 min readMongoDB $mod Operator1 min readMongoDB $sqrt Operator2 min readMongoDB $pow Operator4 min readMongoDB $exp Operator3 min readMongoDB $log Operator3 min readMongoDB $log10 Operator3 min readMongoDB $ln Operator5 min readField Update OperatorsMongoDB - Field Update Operators5 min readMongoDB - $max Operator4 min readMongoDB - $min Operator5 min readMongoDB - $inc Operator5 min readMongoDB - $mul Operator5 min readMongoDB - Rename Operator ($rename)5 min readMongoDB - Current Date Operator ($currentDate)2 min readMongoDB - $setOnInsert Operator4 min readMongoDB Bitwise Update Operator3 min readArray Expression OperatorsMongoDB - $isArray Operator6 min readMongoDB $size Operator5 min readMongoDB $arrayElemAt Operator5 min readMongoDB $concatArrays Operator4 min readMongoDB $reverseArray Operator5 min readArray Update OperatorsMongoDB $pull Operator5 min readMongoDB - $pop Operator4 min readMongoDB - $pullAll Operator3 min readMongoDB $push Operator5 min readMongoDB - Positional Operator ($)4 min readMongoDB All Positional Operator ($[])4 min readMongoDB - $position Modifier4 min readMongoDB $addToSet Operator3 min readMongoDB - $each Modifier3 min readMongoDB - $sort Modifier4 min readMongoDB - $slice Modifier4 min read Like