// const MongoClient = require('mongodb').MongoClient;
const {MongoClient, ObjectID} = require('mongodb');
MongoClient.connect('mongodb://localhost:27017/your_app', (err, db) => {
if (err) {
return console.log('Unable to connect to MongoDB server');
}
console.log('Connected to MongoDB server');
// Execute code here
});
Delete many
Deletes all documents that match the criteria, DOESN'T return any documents.
db.collection('your_db').deleteMany({query_object}).then((result) => {
console.log(result);
});
Delete one
Deletes the first document that matches the criteria, DOESN'T return that document.
db.collection('your_db').deleteOne({query_object}).then((result) => {
console.log(result);
});
Find one and delete
Deletes the first document that matches the criteria, returns that document.
db.collection('your_db').findOneAndDelete({query_object}).then((result) => {
console.log(result);
});
No hay comentarios:
Publicar un comentario