Create and display the newly created database in MongoDB?

MongoDBDatabaseBig Data Analytics

To create a new database, you need to use the USE command as in the below syntax −

use yourDatabaseName;

To show all databases, you need to use show command. The syntax is as follows −

show dbs;

Let us implement the above syntax in order to create database −

> use onlinecustomertracker;
switched to db onlinecustomertracker

In order to display the newly created database, you need to create collection. Following is the query −

> db.example.insert({Value:10});
WriteResult({ "nInserted" : 1 })

Display all documents from a collection with the help of find() method −

> db.example.find();

This will produce the following output −

{ "_id" : ObjectId("5e9dafade3c3cd0dcff36a4f"), "Value" : 10 }

To display all databases, you can use SHOW command −

> show dbs;

This will produce the following output −

MyDB         0.000GB
admin        0.000GB
config       0.000GB
local        0.000GB
onlinecustomertracker 0.000GB
test         0.006GB
raja
Updated on 12-May-2020 08:53:29

Advertisements