I want to delete all document record from all collection from my database.
You can delete all document in mongodb by simply using db.collectionName.remove( { } )
But if your are using node.js, delete all documents by following way.
MongoClient.connect('mongodb://localhost/mochatests', function(err, db) {
db.collection('contacts', {}, function(err, contacts) {
contacts.remove({}, function(err, result) {
if (err) {
console.log(err);
}
console.log(result);
db.close();
});
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With