A MongoDB collection is a list of MongoDB documents and is the equivalent of a relational database table. A collection is created when the first document is being inserted. Unlike a table, a collection doesn't enforce any type of schema and can host different structured documents.
To perform operations on a MongoDB collection, you'll need to use the collection methods. Let's create a posts
collection and insert the first post. In order to do this, execute the following command in the MongoDB shell:
> db.posts.insert({"title":"First Post", "user": "bob"})
After executing the preceding command, it will automatically create the posts collection and insert the first document. To retrieve the collection documents, execute the following command in the MongoDB shell:
> db.posts.find()
You should see a command-line output similar to what is shown in the following screenshot:
This means that you have successfully created the posts
collection and inserted your first document...