MongoDB Basics : Delete a Database in MongoDB


To learn how to drop database in MongoDB programmatically.


Step 1

Create a databases.txt file that contains a list of databases to delete.

Step 2

Create a clean.rb:

require 'mongo'

include Mongo

# Read the database name in the junk.txt
file = File.readlines('/path/to/the/list/of/file/to/delete/databases.txt')

# Drop the database
file.each do |line|
  client =[ '' ], :database => "#{line.chomp.strip}")

This will save you lot of time when you have to delete many databases in MongoDB.


In this article you learned how to delete database in MongoDB and avoid wasting time in MongoDB console to delete databases by running use database and drop database commands.

Related Articles

Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.