Creating a MongoDB a collection

As a collection belongs to a single database so first we will have to create a database for creating a collection

STEP 1: First run the following command into your mongo shell or command prompt

mongo

STEP 2: Check all the existing databases by using the following command

show dbs

STEP 3: Creating a database Here we are creating a database named as- w3wiki

use w3wiki

If the database w3wiki is present it will switch to it, else it will create a new database name as w3wiki and then switch to it as shown below.

STEP 4: Create a Collection

Collection is created using createCollection() method.Collection name is passed as argument in the method.

Syntax:

db.createCollection(‘Collection_name’);

Example : Create Student Collection

Query:

db.createCollection(‘Student’);

Create a collection

Defining, Creating and Dropping a MongoDB collection

MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data.

Similar Reads

Document

It is the basic unit of MongoDB and a single record inside a collection is known as a document. It is a JSON object which has the data in the form of key-value pairs....

Collection

It is the grouping of documents. A collection belongs to a single database inside MongoDB. The collection the contains the data in the form of document just like the table of RDBMS which contains the data in the form of rows and columns....

Creating a MongoDB a collection

As a collection belongs to a single database so first we will have to create a database for creating a collection...

Inserting Documents in the Collection

Inserting only one document at a time...

Editing a collection

...

Dropping the collection

...

Contact Us