Skip to main content

easy

MongoDB Easy​

What is MongoDB?

1. MongoDB is the NoSQL database that provides to store large amount of unstructured data.
2. It works over the Document and Collection concept.
3. MongoDB stores data in flexible, JSON-like documents with dynamic schemas, a format known as BSON (Binary JSON).
4. The MongoDB database contains collections just like allowed to create multiple databases and multiple collections.

What is BSON? and How it is different from JSON?

BSON stands for Binary JSON (Javascript Object Notetion). It is used to transmit and store data across web based applications. It has similarities with JSON for instance BSON .


For Ex.
{
"_id": ObjectId("5f5a8f8e8216b52e5e9a0374"),
"name": "John Doe",
"age": 30,
"email": "[email protected]",
"isStudent": false,
"grades": [85, 92, 78, 90],
"address": {
"street": "123 Main St",
"city": "Anytown",
"zipcode": "12345"
}
}

Difference between JSON and BSON

JSON :

1. JSON files are written in text format.
2. It is use to transmit of data.
3. It is slow as compared to BSON.
4. It has limited set of data types, including objects, arrays, strings, numbers, booleans, and null.

BSON :

1. BSON files are written in binary.
2. Databases use BSON to store data.
3. It is Faster than JSON.
4. It Extends JSON with additional data types such as binary data, date, regular expression, ObjectId .

What is ObjectId in MongoDB?

In MongoDB, each document in a collection is required to have a unique identity known as "ObjectId". The _id field is the key and used as the primary key for the documents in a collection. it is unique identifier for each document. an object id is 12 byte BSON type hexadecimal string having the structure as shown in example.

_id : ObjectId(6009c0eee65f6dce28fb3e50)
What is collection in MongoDB?

In MongoDB, a collection is a group of MongoDB documents. It allow flexibility structure in stored documents.

What is document in MongoDB?

It is a JSON-like BSON (Binary JSON) object that consists of key-value pairs. BSON is a binary representation of JSON-like documents. A document in MongoDB is essentially a set of key-value pairs, where the keys are strings (field names) and the values can be various data types value.