MongoDB – Overview of collection and document
MongoDB is a NoSQL, document-oriented database designed to store, retrieve, and manage large volumes of semi-structured or unstructured data. Unlike traditional relational databases that store data in tables and rows, MongoDB uses a more flexible model, where data is stored in documents (in BSON format), which is a binary form of JSON. These documents are organized into collections, which are roughly equivalent to tables in relational databases.
MongoDB – Collection and Document (In Short)
- Document:
- A document in MongoDB is a basic unit of data and is similar to a row in relational databases.It is stored in a BSON (Binary JSON) format, which is a binary representation of JSON (JavaScript Object Notation).A document can contain key-value pairs, where values can be strings, numbers, arrays, nested documents, or other data types.Documents are schema-less, meaning different documents in the same collection can have different structures.
{
"name": "John Doe", "age": 30,
"address":
{ "street": "123 Main St",
"city": "Springfield" },
"skills": ["JavaScript", "MongoDB"]
}
- Collection:
- A collection in MongoDB is a group of documents. It is similar to a table in relational databases.Collections are schema-less, meaning that they can hold documents with varying structures.Collections are created automatically when documents are inserted, and there is no need to define the structure beforehand.
- In MongoDB:
- users is a collection that could store many user documents.
Summary:
- Document: A single record in MongoDB, similar to a row in a relational database.
- Collection: A grouping of documents, similar to a table in a relational database.
Recent Comments