how to create database in mongodb?

Today, We want to share with you how to create database in mongodb.In this post we will show you mongodb create database with username and password, hear for create collection in mongodb we will give you demo and example for implement.In this post, we will learn about MongoDB CRUD Tutorial With Example From Scratch with an example.

MongoDB Create Database

there are Installing MongoDB creates 3 default main databases:

  • Admin
  • Config
  • Local

The use Command

Basic syntax

use DATABASE_NAME

Example

>use mydb
switched to db mydb

Get databases list

>show dbs
local     0.78125GB
pakainfo      0.23012GB

Creating a MongoDB Database with the CLI

> show dbs
admin 0.000GB
local  0.000GB

Start the MongoDB service

net start MongoDB

The MongoDB service is starting..
The MongoDB service was started successfully.

creating a collection user and inserting a document in it.

> db.user.insert({name: "Chaitanya", age: 30})
WriteResult({ "nInserted" : 1 })
> show dbs
admin          0.000GB
pakainfowebdo  0.000GB
local          0.000GB

Creating a Collection/Table using insert()

The Field Names of the document are “Memberid” and “MemberName” and the Field values are “1” and “Meera’ respectively. A bunch of documents would then make up a collection in MongoDB.

db.Member.insert
(
	{
		"Memberid" : 1,
		"MemberName" : "Pankitsh"
	}
)

I hope you get an idea about how to create database in mongodb.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment