Remove by _id in MongoDB console

前端 未结 11 1242
野的像风
野的像风 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条回答
  •  梦毁少年i
    2020-12-22 17:05

    Do you have multiple mongodb nodes in a replica set?

    I found (I am using via Robomongo gui mongo shell, I guess same applies in other cases) that the correct remove syntax, i.e.

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

    ...does not work unless you are connected to the primary node of the replica set.

提交回复
热议问题