MongoDB drop every database

后端 未结 8 1088
清歌不尽
清歌不尽 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 19:48

    var mongo = db.getMongo(); mongo.getDBNames().filter(n => n != 'admin' && n != 'local' && n != 'config').forEach(function (dbname) { var db = mongo.getDB(dbname); db.dropDatabase(); });

    This one is safe to copy and execute on mongoshell. Credits to all answers above. Just exclude 'config' database as well.

提交回复
热议问题