MongoDB drop every database

后端 未结 8 1122
清歌不尽
清歌不尽 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条回答
  •  你的背包
    2021-01-29 19:57

    you can create a javascript loop that do the job and then execute it in the mongoconsole.

    var dbs = db.getMongo().getDBNames()
    for(var i in dbs){
        db = db.getMongo().getDB( dbs[i] );
        print( "dropping db " + db.getName() );
        db.dropDatabase();
    }
    

    save it to dropall.js and then execute:

    mongo dropall.js
    

提交回复
热议问题