Flexibility of Schema with MongoDB

Posted By : Rohit Godara | 10-Oct-2018

The key challenge in knowledge modeling is leveling the wants of the applying, the performance characteristics of the info engine, and also the knowledge retrieval patterns. once coming up with knowledge models, continuously think about the applying usage of the info (i.e. queries, updates, and the process of {the knowledge|the info|the information}) still because of the inherent structure of the data itself.

 

Flexible Schema

Unlike SQL databases, wherever you need to confirm and declare a table’s schema before inserting knowledge, MongoDB’s collections, by default, doesn't need its documents to possess identical schema. That is:

 

The documents in a very single assortment don't have to be compelled to have the identical set of fields and therefore the knowledge sort for a field will dissent across documents inside a set.


To change the structure of the documents in a very assortment, like add new fields, take away existing fields, or modification the sphere values to a replacement sort, update the documents to the new structure.

 

Document Structure

The key call in planning information models for MongoDB applications revolves around the structure of documents and the way the applying represents relationships between information. MongoDB permits connected information to be embedded in one document.

 

Embedded information

Embedded documents capture relationships between information by storing connection information in a very single document structure. MongoDB documents create it attainable to embed document structures in a very field or array among a document. These denormalized information models permit applications to retrieve and manipulate connected information in a very single info operation.

{
	_id: [objectid],
	username:"abc",
	address:{
				street:"abc@123",
				city:"Delhi",
				pincode:12345
			}
	contact:{
				phone:"123-456-7890"
				email:"[email protected]"
			}		
}

Atomicity of Write Operations

Single Document Atomicity : In MongoDB, a write operation is atomic on the amount of one document, though the operation modifies multiple embedded documents inside one document.

A denormalized knowledge model with embedded knowledge combines all connected knowledge in a very single document rather than normalizing across multiple documents and collections. This knowledge model facilitates atomic operations.

About Author

Author Image
Rohit Godara

Rohit is always ready to face challenges and likes to work with full dedication and coordination. He is always eager to learn new technologies so as to develop his skills and knowledge.

Request for Proposal

Name is required

Comment is required

Sending message..