MONGODB Tutorial



MongoDB COLLECTION


📂 MongoDB Collections

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.

🔹 Creating a Collection

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.

📥 Example: Insert Document (Auto-Creates Collection)

db.employees.insertOne({
  name: "Neha Sharma",
  position: "Developer",
  age: 27
});
  

This command automatically creates the employees collection and adds a document to it.

🔍 View All Collections in a Database

show collections
  

Displays all collections in the current database.

💡 Tip: Collections do not require a predefined schema. You can store different types of documents in the same collection.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review