MongoDB create database

Published on 2024-11-23 by Raul

MongoDB it getting more and more popular. Since its paradigm is a lot different from sql, many people have issues starting up.

I am planning on writing a couple of posts on MongoDB and its configuration in the future, so stay tuned.

Let's open a mongo shell (just double click on mongo.exe) and type

show dbs

 This will show you a list of available databases.

In order to CREATE a database, use

use WhateverDatabase

 Now, if you go and type "show dbs" again, you'll see that WhateverDatabase is not listed. That's because this database does not exist yet. To create it, you must create a collection(table in sql paradigm):

db.MyCollection.insert({"name":"webstein", "age":3})

 Once the collection is created, the database is also created. To check, use show dbs again.


Keep in touch


About

Hey there, I'm Raul, owner of CreativeCLR, a small consulting company.

Feel free to drop me any question you might have on this post using the comment section or the contact page.