Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • MongoDB - Get Started
  • What is MongoDB?
  • Install MongoDB
  • MongoDB Server
  • MongoDB Shell
  • MongoDB Shell Commands
  • MongoDB Compass
  • MongoDB Database
  • MongoDB Collections
  • MongoDB Documents
  • Insert Single Document
  • Insert Multiple Documents
  • Import Data into Collection
  • Find Single Document
  • Find Multiple Documents
  • MongoDB Cursor
  • MongoDB Sort Documents
  • Update Single Document
  • Update Multiple Documents
  • Update Arrays
  • Update Embedded Documents
  • Delete Documents
  • Relations in MongoDB
  • Aggregation in MongoDB
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

MongoDB Collections

A collection in MongoDB is similar to a table in RDBMS. MongoDB collections do not enforce schemas. Each MongoDB collection can have multiple documents. A document is equilant to row in a table in RDBMS.

To create a collection, use the db.createCollection() command. The following creates a new employees collection in the current database, which is humanResourceDB database created in the previous chapter.

Create Collection

Above, the employees collection is created using the creatCollection() method. It returns an object { ok: 1 }, which indicates the collection was created successfully.

As mentioned above, a single database can have multiple collections. The following creates multiple collections.

Create Multiple Collections

Use the show collections commands to list all the collections in a database.

Show Collections

To delete a collection, use the db.<collection-name>.drop() method.

Delete Collection

Create Collection in MongoDB Compass

To create a new collection using MongoDB Compass, connect compass to your server and select the database.

Click on the "Create Collection" button to create a new collection, as shown below.

MongoDB Compass - Collections

Enter the name of a collection, check appropriate checkbox and click on the Create Collection button to create it.

MongoDB Compass - Collections

Thus, you can create a new collection using MongoDB Shell mongosh or MongoDB Compass.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.