Tutorials References Exercises Bootcamp Menu
Sign Up Create Website Get Certified Upgrade

MongoDB mongosh Create Collection

Create Collection using mongosh

There are 2 ways to create a collection.

Method 1

You can create a collection using the createCollection() database method.


Try it Yourself »

Method 2

You can also create a collection during the insert process.


We are here assuming object is a valid JavaScript object containing post data:

Try it Yourself »

This will create the "posts" collection if it does not already exist.

Remember: In MongoDB, a collection is not actually created until it gets content!