For system, network and cloud administrators
Once you’ve installed MongoDB on your system, these are the steps for creating a MongoDB.
mongod
service is running first:sudo systemctl status mongod.service
If the service is not running then you’ll need to start the service and check the status of it again:
sudo systemctl start mongod.service
sudo systemctl status mongod.service
MongoDB
console just by typing in your terminal:mongo
> use a_name_of_your_choosing;
The console will then tell you it switched to the database you’ve just created. But to test that at this point you’re using the correct database, type:
> db;
The name of your database should be the output. Now, in order to be able to actually start using this newly created database, you’ll need to actually insert data into your MongoDB database so that the service will be able to display it to you when using the show dbs;
command. This means that the following step is crucial in order to finalize the creation of your MongoDB database.
> db.favoriteanimals.insert({"name":"Foxy fox"});
The output of the command above should be similar to: WriteResult({ "nInserted" : 1 })
.
> show dbs;
If the name of your database is shown in the output then you’ve successfully created your first MongoDB database.