MongoDB drop every database

后端 未结 8 1021
清歌不尽
清歌不尽 2021-01-29 19:30

I would like to know if there\'re a command to drop every databases from my MongoDB?

I know if I want to drop only one datatable, I just need to type the name of the dat

8条回答
  •  旧时难觅i
    2021-01-29 20:09

    You can also do this with a simple mongo command:

    db.adminCommand("listDatabases").databases.forEach( function (d) {
        if (d.name != "local" && d.name != "admin"  && d.name != "apiomat"  && d.name != "config")
            db.getSiblingDB(d.name).dropDatabase();
     })
    

提交回复
热议问题