Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

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.

Example

db.createCollection("posts")
Try it Yourself »

Method 2

You can also create a collection during the insert process.

Example

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

db.posts.insertOne(object)
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!