Remove by _id in MongoDB console

前端 未结 11 1255
野的像风
野的像风 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 17:13

    Solution and Example:

    1- C:\MongoDB\Server\3.2\bin>mongo (do not issue command yet because you are not connected to any database yet, you are only connected to database server mongodb).

    2-

    show dbs analytics_database 0.000GB local 0.000GB test_database 0.000GB

    3-

    use test_database switched to db test_database

    4-

    db.Collection.remove({"_id": ObjectId("5694a3590f6d451c1500002e")}, 1); WriteResult({ "nRemoved" : 1 })

    now you see WriteResult({ "nRemoved" : 1 }) is 1 not 0.

    Done.

提交回复
热议问题