Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb: Remove all document form all collection [duplicate]

I want to delete all document record from all collection from my database.

like image 209
Hardik Mandankaa Avatar asked Oct 23 '25 17:10

Hardik Mandankaa


1 Answers

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();
        });
    });
});
like image 189
Radhesh Vayeda Avatar answered Oct 26 '25 07:10

Radhesh Vayeda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!