MongoDB #2 Database

Think Internet GmbH
Aug 9, 2017 · 2 min read

After we’ve successfully installed our first MongoDB instance we’re now able to create databases and collections. If you don’t have a MongoDB instance yet read my previous article (https://medium.com/timhaag/mongodb-1-installation-507c6850410a). In this article I’ll show you how to interact with your MongoDB instance in terms of databases.

Let’s get started!

Connect to your MongoDB (running on the default Port 27017) using:

mongo

To list all your current databases within this instance use:

show dbs

You’ll see all the databases with their sizes in GB. To create a new database you don’t have to give MongoDB something like a structure or anything like that. You simply tell MongoDB you want to use a specific database regardless if it already exists or not. To use/create a database simply type:

use test

If you want to use/create “test” as your database. You’re now able to access all the information within that database. To switch to another database even if you’re in use of “test” for example you could use the same command to simply switch between databases. To delete your database just use:

db.dropDatabase()

NOTE: To drop your database you have to “use” the database (using “use test” as explained above)

To see which collections are within your database just use:

show collections

That’s it for MongoDB databases for now. Stay tuned for the next article to learn about collections, what they’re used for and how do you use them.

Written by

We're building scalable web applications and apps.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade