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 check the version of MongoDB?
- How to use watch in MongoDB?
- How to update one document in MongoDB?
- How to update many documents in MongoDB?
- How to use MongoDB queue?
- How to create a many to many relation in MongoDB?
- How to insert new document into MongoDB?
- How to use hint in MongoDB?
- How to work with time series data in MongoDB?
- How to use unwind in MongoDB?
See more codes...