MongoDB collections

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 ...

Get MEAN Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.