>_ Dinesh Sawant

The Story of MongoDB : Two universes

// PUBLISHED:
•
// DURATION: 2 min read
• DRAFT_ENTRY

Story 1

Rajesh recently learned about MongoDB. He developed few tutorial projects using MongoDB and understood most of the concepts.

Rajesh decided to use MongoDB for the new project they were starting in his company. Rajesh created a users collection in MongoDB to store user data.

{
	"username": "tony",
	"age": 35,
	"role": "superuser",
	"full_name": "Anthony Edward Stark",
	"last_seen": "2019-04-22"
}

Rajesh used his favourite programming language to insert/update this data. But after pushing the code to production he found there was a bug. One of the code flow was inserting age as array i.e. [35] instead of integer value. This bug was not surfaced during testing. In production, he found 50% of user entries were corrupted due to the bug.

Rajesh fixed his code. Fixed corrupted data. Deployed the hot-fix to production.

But Rajesh was not impressed with this activity. He thought if MongoDB could have validated the documents, this corruption of data could have been prevented. Thankfully, there is a feature for schema validation in MongoDB.

Rajesh added a JSON schema validator to users collection. Now he was able to sleep at night without worrying about data corruption. As days passed by, new fields were introduced in user collection and more validations were added. It was getting difficult for Rajesh to understand why particular document was failing validation. Because MongoDB does not tell why the document has failed validation.

As finding the reason for invalid document, was getting cumbersome he thought of using Application side validations. He was able to get reason of invalid document using an ORM, which works pretty well for him.

The End!

Story 2 - In Parallel Universe

Rajesh recently learned about MongoDB. He created few tutorial projects using MongoDB and understood most of the concepts.

Rajesh decided to use MongoDB for the new project they were starting in his company. But before implementing any of the stuff, he decided to compare how the data model will work in both Postgres and MongoDB. He created a users table in Postgres.

username age role full_name last_seen
tony 35 superuser Anthony Edward Stark 2019-04-22

Rajesh realised that there are no advantages of using MongoDB for storing users data and he settled with Postgres. He may use MongoDB in future for appropriate use case.

The End!

// BROADCAST_POST: