What is a MongoDB collection? If you are familiar with RDBMSes, a collection is akin to an RDBMS table, which can consist of different fields, except the enforcement of schema. We use the createCollection method to create a collection with the following format:
> db.createCollection(<name>, <options>)
The <name> parameter is the name of the collection, such as user, article, or whatever. The <options> parameter is optional, and is used to specify fields for creating a fixed-sized collection, or a collection that validates updates and inserts. For more information about these options, please visit https://docs.mongodb.com/manual/reference/method/db.createCollection/. Let's create a document and see what else you can do with the document in the following steps:
- Create a collection without any options:
> db.createCollection("users", {})
You should get the following result:
{ "ok" : 1 }
- List all collections...