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 check the version of MongoDB?
- How to work with time series data in MongoDB?
- How to update many documents in MongoDB?
- How to update an array element in MongoDB?
- How to use triggers in MongoDB?
- How to use unwind in MongoDB?
- How to list MongoDB users?
- How to remove a field from MongoDB?
- How to use MongoDB queue?
See more codes...