MongoDB #2 Database

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:
mongoTo list all your current databases within this instance use:
show dbsYou’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 testIf 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 collectionsThat’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.
