Collections in Mongo DB


Collections in Mongo DB

A collection of MongoDB is a group of documents. A collection in MongoDB is similar to a table in a relational SQL database. A collection in MongoDB is a basic component that contains the same set of documents. A collection in MongoDB is similar to a table in a relational SQL database. Similarly, MongoDB documentation is identical to a row in a relational SQL database. The collection does not need to exist in the database before you can insert the document into MongoDB.

From your programming language, when you add the first document in a collection and the provided collection does not exist in that database, MongoDB creates a new collection. So you can say, for insertion of the document, collection need not be present in MongoDB.

Types of MongoDB Collection

In MongoDB, there is various type of collections: Normal collection for holding a normal collection, Capped Collection for Queue data, TTL collection for caching data system collection, this is a predefined collection, GridFS collection for large file data storage indexed collection, Geospatial collection for lat and long or 2D data or spherical data complete text search collection for simple text/string search MongoDB collection and Dynamic Schema.

You can found every row can have different types of documents; in this way, MongoDB does not need collection. If you keep all the documents in one collection, logically, you can keep them, but management became hell in this way. In programming languages, you need to create some loops to see which group this document belongs to, and so on. There are several reasons why you requested a collection in MongoDB.

  • Group documents into collections.
  • Fater is getting a group of documents from a collection Locality of the same document type data.
  • More efficient indexing with MongoDB engine.

MongoDB collection naming convention

  1. The collection name is a UTF8 string.
  2. An empty string, i. H. "is not a valid collection name.
  3. The collection name cannot contain null characters. H. \ o, because this character is used at the end of the key Collection names do not start with the system.
  4. Because of the system, it is a reservation keyword.
  5. Example: system. users contain a user database. Database tables are unique because MongoDB collections are unique. There can be multiple collections in the database. MongoDB collections and dynamic, MongoDB doesn't need a collection because each row can contain different types of documents. If you keep all your documents in one collection, you can keep them logically, but management has become hell. In programming languages, you need to create some loops to see which group this document belongs to, and so on. There are several reasons why you requested a collection in MongoDB. Group documents into collections fatter.