MongoDB TutorialLesson 5Free preview
MongoDB Collection
This lesson is part of MongoDB · All levels
Summary
This lesson explains how to create a collection in mongosh, both explicitly with db.createCollection() and automatically when first inserting a document. Collections can be created with options like capped or validator to limit content. Knowing the collection list helps ensure the database structure that governs it.
Key points
- Db.createCollection("name") makes the collection explicitly
- The collection is also automatically formed when the first insert is made.
- Db.getCollectionNames() displays a list of collections in the active database
- Options like validators can be added when creating a collection
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.