demo_delete.js:
var MongoClient = require('mongodb').MongoClient; var url = "mongodb://localhost:27017/"; MongoClient.connect(url, function(err, db) { if (err) throw err; var dbo = db.db("mydb"); /*Delete the first customers with the address "Mountain 21":*/ var myquery = { address: 'Mountain 21' }; dbo.collection("customers").deleteOne(myquery, function(err, obj) { if (err) throw err; console.log("1 document deleted"); db.close(); }); });
C:\Users\My Name>node demo_delete.js
1 document deleted