Node JS - Node js MongoDB Remove - MongoDB delete records - MongoDB - Node - Node JS tutorial - webnode
How to Remove of MongoDB in Node.js?
- The remove() method returns an object which contains information about how the execution affected the database.
- In this, You can delete records, or documents as it is called in MongoDB, by using the remove() method.
- The first parameter of the remove() method is a query object defining which documents to delete.


Example
Remove the record of employee whose address is hussain. Create a js file named "remove.js", having the following code:
remove.js
var http = require('http');
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/ MongoDatabase";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var myquery = { address: 'hussian' };
db.collection("employees").remove(myquery, function(err, obj) {
if (err) throw err;
console.log(obj.result.n + " record(s) deleted");
db.close();
});
});
Open the command terminal and run the following command: Node remove.js
Output:

Learn Node js - node js Tutorial - remove procedure of mongodb in node.js - node - Node js Examples
Related nodejs article tags - node js - node js tutorial - node js examples
Verification
You can check that the record having address "hussain" is deleted and only following records are available now:

Learn Node js - node js Tutorial - verification of remove mongodb in node.js remove - node - Node js Examples