 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to exclude array type field value in MongoDB?
To exclude array type field value, use delete() in MongoDB. Let us create a collection with documents −
> db.demo464.insertOne( ... { ... ...    "id" : "101", ...    "details": [ ...       { ...          Name:"Chris" ...       }, ...       { ...          Name:"David" ...       } ...    ] ... } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5e7f8832cb66ccba22cc9dda") } Display all documents from a collection with the help of find() method −
> db.demo464.find();
This will produce the following output −
{ "_id" : ObjectId("5e7f8832cb66ccba22cc9dda"), "id" : "101", "details" : [ { "Name" : "Chris" }, { "Name" : "David" } ] } Following is the query to exclude array type field values −
> db.demo464.find({id: "101"}).forEach(function(mongoDocument) { ... ... var details = mongoDocument.details; ... for(var j = 0; j − details.length; ++j) { ... var array = details[j]; ... delete (array["Name"]); ... ... } ... db.demo464.save(mongoDocument); ... }); Display all documents from a collection with the help of find() method −
> db.demo464.find();
This will produce the following output −
{ "_id" : ObjectId("5e7f8832cb66ccba22cc9dda"), "id" : "101", "details" : [ { }, { } ] }Advertisements
 