4
expressとmongodbでidで文書を削除したい findOneAndDelete()は_idで削除できません。どうして ?mongodbの相違点remove()とdeleteOneAndDelete()とdeleteOne()との比較
db.collection('quotes').findOneAndDelete({name: req.body.name}, (err, result) => {
if (err) return res.send(500, err)
})
var ObjectId = require('mongodb').ObjectId;
var collection = db.collection('quotes');
collection.remove({_id: new ObjectId(req.body.id)}, function(err, result) {
if (err) {
console.log(err);
} else {
res.send('A darth vadar quote got deleted')
}
});
var mongodb = require('mongodb');
db.collection('quotes', function(err, collection) {
collection.deleteOne({_id: new mongodb.ObjectID(req.body.id)});
});
3つの機能の違いは?要するに