How to get removed document in MongoDB?

前端 未结 2 875
再見小時候
再見小時候 2020-12-04 01:58

Is it possible to get the document that was removed from MongoDB?

result = db.things.remove({_id: id})
// is there a result.removedObjects?

2条回答
  •  长情又很酷
    2020-12-04 02:11

    db.collection('mycollection').findOneAndDelete({
        id: '123456'
    }, function (error, response) {
        response.value;// returns the deleted object, but no longer exists in the database
    });
    

提交回复
热议问题