How To Create Database In MongoDB 4.2 On CentOS / Redhat 7

0
189

Let’s see how to create a database in MongoDB 4.2. We can check and create a user in the MongoDB database server and also show users using the command line in MongoDB.

Mongodb's crossed-platform document-oriented database program. I have
installed MongoDB 4.2 version on Linux Server using the repository from MongoDB
site. 

Check Out: Installation Of MongoDB Database Server

How To Create Database In MongoDB 4.2 On CentOS / Redhat 7:

MongoDB database is also known as the NoSQL database program andMongoDB
uses JSON like documents with the schema.

Step 1: Login MongoDB console using below command

mongo

Check all database,

show dbs

Step 2: Create a database, this will create a ‘test’ database if not present and you can also use the same command to switch the database.

use test

As you can see the ‘test’ database is not present. This will not appear until you don’t write at least one document in this database.

You can check your current database where you’re by ‘db’.

Create Database In MongoDB

Step 3: Now you need to add at-least one data in the ‘test’ database.

db.user.insert({name: “deloa”, age: 20})

mongodb database

Step 4: Check your database will appear here.

show dbs

mongodb check database

if you want to drop this database, So we can’t specify the database name to drop it. What we can do. Use the database you want to drop and run the below command.

db.dropDatabase()

show user in mongodb

YouTube Link: Database Create In Mongodb 4.2

You’re done. show user in mongodb create

LEAVE A REPLY

Please enter your comment!
Please enter your name here