MongoDB
MongoDB Basics
CRUD Operations
Insert
Find
Update
Delete
Query Operators
Comparison Operators
Logical Operators
Element Operators
Create collection in MongoDB
To create a collection in MongoDB, you can use the db.createCollection()
method in the MongoDB shell. The syntax for creating a collection is as follows:
Where <collection_name>
is the name of the collection you want to create and <options>
are the optional parameters that you can use to configure the collection. Here are some examples of how you can create a collection:
Create a collection without any options:
This will create a collection named "users" in the current database.
Create a collection with options:
This will create a capped collection named "users" with a maximum size of 100,000 bytes and a maximum number of documents of 100.
You can also create a collection using the MongoCollection
class in a MongoDB driver for your programming language. The specific syntax for doing this will depend on the driver you are using.
Last updated