mongodbHow to create a collection in MongoDB?
Creating a collection in MongoDB is a simple process. To create a collection, use the db.createCollection()
method. The syntax for this method is as follows:
db.createCollection(name, options)
name
: The name of the collection to be created.options
: This is an optional parameter. It is a document that specifies the configuration of the collection.
Example
db.createCollection("customers", { capped : true, autoIndexId : true, size : 6142800, max : 10000 } )
Output example
{ "ok" : 1 }
Helpful links
More of Mongodb
- How to use watch in MongoDB?
- How to list all indexes in MongoDB?
- How to create a many to many relation in MongoDB?
- How to join two collections in MongoDB?
- How to check the version of MongoDB?
- How to list MongoDB users?
- How to use MongoDB push?
- How to empty an array in MongoDB?
- How to find by id in MongoDB?
- How to update an array element in MongoDB?
See more codes...