
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to remove a specific element from array in MongoDB?
To remove a specific element, use $pull. Let us create a collection with documents −
> db.demo125.insertOne({"ListOfNames":["John","Chris","Bob","David","Carol"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f304068e7f832db1a7f55") }
Display all documents from a collection with the help of find() method −
> db.demo125.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5e2f304068e7f832db1a7f55"), "ListOfNames" : [ "John", "Chris", "Bob", "David", "Carol" ] }
Following is the query to remove a specific element from array in MongoDB −
> db.demo125.update( ... { }, ... { $pull: { ListOfNames: { $in: [ "David"] }} }, ... { multi: true } ... ) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo125.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5e2f304068e7f832db1a7f55"), "ListOfNames" : [ "John", "Chris", "Bob", "Carol" ] }
- Related Articles
- How to remove Specific Element from a Swift Array?
- How to remove a specific element from a JSON Array in Java?
- How to remove element in a MongoDB array?
- Remove null element from MongoDB array?
- How to remove array element in MongoDB?
- How to remove an element from a doubly-nested array in a MongoDB document?
- MongoDB query to match and remove element from an array?
- MongoDB query to remove element from array as sub property
- How to remove object from array in MongoDB?
- Remove a specific element from a LinkedList in Java
- MongoDB query to get record beginning with specific element from an array?
- How to remove an array element by its index in MongoDB?
- How to get a particular element from MongoDB array?
- How to delete/remove an element from a C# array?
- How to get a specific object from array of objects inside specific MongoDB document?

Advertisements