In MongoDB, a collection is a group of documents, similar to a table in relational databases. However, collections are more flexible, as documents in the same collection can have different fields.
Collections are automatically created when you insert your first document. But you can also create them manually using:
db.createCollection("students")
This creates a new collection named students
in the current database.
db.employees.insertOne({ name: "Neha Sharma", position: "Developer", age: 27 });
This command automatically creates the employees
collection and adds a document to it.
show collections
Displays all collections in the current database.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!