mongosh Create Collection
Create Collection using
There are 2 ways to create a collection.
You can create a collection using the
createCollection() database method.
db.createCollection("posts")Try it Yourself »
You can also create a collection during the
We are here assuming
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!