mongodb difference remove() vs findOneAndDelete() vs deleteOne()

前端 未结 1 1792
清酒与你
清酒与你 2021-02-02 11:28

In express and mongodb I want delete document by id findOneAndDelete() Can not delete by _id, can only delete by field ! why ?

db.collection(\'quotes\').findOneA         


        
1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-02 11:57

    In short:

    • findOneAndDelete() returns the deleted document after having deleted it (in case you need its contents after the delete operation);
    • deleteOne() is used to delete a single document
    • remove() is a deprecated function and has been replaced by deleteOne() (to delete a single document) and deleteMany() (to delete multiple documents)

    findOneAndDelete() should be able to delete on _id.

    0 讨论(0)
提交回复
热议问题