Remove by _id in MongoDB console

前端 未结 11 1169
野的像风
野的像风 2020-12-22 16:14

In the MongoDB console how can I remove a record by id? Here\'s my collection :

[ 
  {
     \"_id\" : { \"$oid\" : \"4d512b45cc9374271b02ec4f\" },
     \"nam         


        
11条回答
  •  时光说笑
    2020-12-22 16:54

    Very close. This will work:

    db.test_users.deleteOne( {"_id": ObjectId("4d512b45cc9374271b02ec4f")});
    

    i.e. you don't need a new for the ObjectId.

    Also, note that in some drivers/tools, remove() is now deprecated and deleteOne or deleteMany should be used instead.

提交回复
热议问题