Remove only one document in MongoDB

后端 未结 9 2004
日久生厌
日久生厌 2021-01-12 23:42

when I call

db.collection.remove({\'condition\':\'some condition\'});

This one line will delete all the matching condition documents.

9条回答
  •  走了就别回头了
    2021-01-12 23:57

    If there are multiple records and you want to delete only first record, then set justOne parameter in remove() method.

    Here, you want to delete only 1. Thus, set "justOne" parameter as 1.

    db.collection.remove({'condition':'some condition'},1);

提交回复
热议问题