Create Collection in MongoDB

How to Create a Collection in MongoDB?

April 3rd, 2026
2092
11:00 Minutes

Database management systems (DBMS) are in a great demand these days. Its market size was estimated at USD 100.79 billion in 2023 and is expected to grow exponentially. Currently it has a market share of 45.68%. This is why it is an important skill where one can create a collection in MongoDB or learn to use it efficiently.

It is even considered one of the best alternatives for traditional relational databases due to its functionalities. This tool manages, stores and retrieves document-oriented information on the go. There are many features too like non-parameterized queries, load distribution, cataloging and JavaScript execution. Explore this article to learn how to create a collection in MongoDB.

Explore other igmGuru's Big Data Certification Courses to enhance your skills.

What is Document in MongoDB?

Let us understand what is a document in MongoDB. Document is the basic building block of a collection in MongoDB. It is a record that contains information in the form of field and value pairs. It is basically a JSON object. Documents can contain a single or many fields or value pairs. The field name is represented by strings. The value is named by arrays and has a specific data type.

What is a Collection in MongoDB?

One needs to know 'What is a collection in MongoDB' before learning to create them. A group of documents stored in a single database is known as a collection. Collections have many similarities to tables of relational databases. One of the major distinctions between them is they do not have any schema. This means that all documents within a collection can possess different structures.

Related Article - How to Install MongoDB on Windows

Steps to Create a Collection in MongoDB

Many individuals have misconceptions that creating a collection in MongoDB is complicated. It is because companies use this tool to manage humongous databases. But it is not so complicated. The following are the steps to create a collection in MongoDB -

Step 1 - Create a Database

Databases in MongoDB are created using the use command. This command either builds a new database or accesses an existing one. One must have to input some data to create a new database if it does not exist. Data inputting is a must to create a new database.

# Syntax

use database_name

# Example

useigmguru

Step - 2 Create a Collection in MongoDB

There are many methods of creating a collection in MongoDB. We will use the createCollection() method in this instance. It is important to note that we have to insert at least one document first in order to create a collection. The system will not take the command unless it does not have any documents to store.

# Syntax

db.createCollection('collection_name' );

# Create a Collection

db.createCollection('Student');

# Insert the first document

db.Student.insertOne({Name: "Om", age: 19})

# Output

test> use igmguru;

switched to db igmguru

igmguru> db.createCollection('Student');

{ ok: 1 }

igmguru> db. Student.insertOne({Name:"Om", Age: 19});

{

acknowledged:

true,

insertedId: ObjectId("65a66db13cfbaabe01a3670b")

}

igmguru> db. Student.find();

[ { id: ObjectId("65a66db13cfbaabe01a3670b"), Name: 'Om', Age: 19}]

igmguru>

Step 3 - Insert Documents in the Collection in MongoDB

Now it is time to insert all the documents in the collection. One can insert as many as they want too. The only restriction is that they should be in JSON-like format. There are many methods to perform this task. We are using two of the most reliable.

1. insertOne() Method

# Syntax

db.collection_name.insertOne({ field1: value1, field2: value2, … });

# Example

db.myNewCollection1.insertOne( { name:"igmguru" } )

# Output

> db.myNewCollection1.insertOne() { name: "igmguru" })

{

"acknowledged":

true,

"insertedId" : ObjectId("6017a92c0cf217478ba93593")

}

2. insertMany() method -

# Syntax

db.collection_name.insertMany([{ field1: value1, field2: value2, ... }, { field1: value1, field2: value2, ... }, ... ]);

# Example

db.myNewCollection2.insertMany([{name:"gfg", country:"India"}, {name:"rahul", age:20}])

# Output

> db.myNewCollection2.insertMany ([{name:"gfg", country: "India"}, {name:"rahul",

age: 20}])

{

"acknowledged":

true,

"insertedIds":[

ObjectId("6017a97d0cf217478ba93594"),

ObjectId("6017a97d0cf217478ba93595")

]

}

>

Step - 4 Check Existing Collections

It is also important to check all the collections in MongoDB. This practice is a must to make sure that we have all the information. Experts check it by listing all the collections with the show collections command.

# Input

show collections

# Output

> show collections

myNewCollection1

myNewCollection2

>

Related Article - Create a Database in MongoDB

Best Practices for Managing Collection in MongoDB

Experts should also be able to manage a collection in MongoDB. They should be aware of the best practices to perform in this instance. These practices are naming conventions, indexing, schema design and data validation. Having knowledge of these can make you a good candidate to learn MongoDB and become an expert.

  • Naming Conventions - Only use meaningful names for collections and databases according to their use or data type. Do not use any uppercase letters and use underscore (_) for spaces within a name.
  • Indexes - This tool can automatically index the _id field for every document. But it will not be enough. Create some additional indexes to perform frequent queries for better performance.
  • Schema Design - This DBMS is indeed a schema-less tool. It is still important to create collections with consistent data. This will remove the complexities.
  • Data Validation - Schema-less tools often lack data integrity. Use its schema validation features to enforce schema for data integrity.

Wrapping Up on How to Create a Collection in MongoDB?

We have discussed all the steps to create a collection in MongoDB through this article. Anyone with basic knowledge of its commands and tools can easily create one. They would require some additional knowledge to move further on this tool. It is recommended to use some additional resources like an online course or a MongoDB tutorial to get more knowledge.

FAQs for 'Create a Collection in MongoDB'

Q1. How are tables different from collections in MongoDB?

There are only a few differences between them. Tables store only structured data whereas collections can also store unstructured data. This data is stored in JSON format. We cannot use collections and joins, unlike tables for advanced analysis.

Q2. How many collections can be stored in MongoDB?

There is no hard limit for storing collections in MongoDB. One can store many of them. But it is recommended to use up to 10,000 per replica set. MongoDB will lack in performance once it reaches this limit.

Q3. What is schema in MongoDB?

This database management system is schema-less according to its nature. It also uses a flexible schema model in some instances. The documents within a collection are not restricted to have the same data types or fields by default. This model makes sure that no unintended schema changes data types.

Course Schedule

Course NameBatch TypeDetails
MongoDB Training
Every WeekdayView Details
MongoDB Training
Every WeekendView Details

About the Author
Nehal Somani
About the Author

Nehal Somani is a technology writer specializing in Machine Learning, Artificial Intelligence, Deep Learning, and Robotic Process Automation. She simplifies complex concepts into clear, practical insights with an engaging style, helping beginners and professionals build knowledge, explore innovations, and stay updated in the fast-evolving tech landscape.

Drop Us a Query
Fields marked * are mandatory
×

Your Shopping Cart


Your shopping cart is empty.