Delete a document

suggest change

Delete a document with the property { greetings: 'Whut?' }. Since driver 3.0, MongoClient.connect passes a client, not a Db.

const MongoClient = require('mongodb').MongoClient;

const url = 'mongodb://localhost:27017';

MongoClient.connect(url, function (err, client) {
    if (err) throw err;
    var db = client.db('test');
    db.collection('myCollection').deleteOne(
        { greetings: "Whut?" },
        function (err, result) {
            if (err) throw err;
            client.close();
        }
    );
});

Collection method deleteOne()

db.collection(collection).deleteOne(filter, options, callback)

Parameter Type Description
filter object A document that selects which documents to delete
options object (optional) Extra settings (default: null)
callback Function Called when the operation finishes

The callback is error-first:

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents