Posts

JavaScript journey: from Zero to Hero

Image
 Initially, many developers felt that JavaScript is an inferior language because of its simplicity. In fact many developers didn’t assume JavaScript as a programming language. JavaScript was only scripting language for them. But after coming ES5 at 2009 and Node.js at 2010, JavaScript started to become very popular among developers. After introducing AJAX (A synchronous J avaScript A nd X ML ) in JS, it became clear that JS allows developers to build powerful and highly responsive web applications. Foremost I would like to thank “ Brendan Eich ” who introduced JavaScript in 1995 during his running project of “ NetScape 2 ”. NetScape was leading browser of that time which was competing with Internet Explorer of Microsoft.   Eich prepared JavaScript in 10 days to bring back NetScape into playground. Initially it was named as LiveScript but later it was renamed as JavaScript under marketing strategy to leverage Java. ECMA which stands for Eur...

Does Mongo DB create _id of document by itself?

Image
This question often confuse some developers, how mongo db creates unique document _id so fast. But the truth is mongo db doesn’t create document _id by itself. Let’s perform a test… I create a model of Boy and then created an object of that model. I print that object on console before saving it on mongo db. 3. But console printed this result.. 4. But this document got _id before saving it on database. Once we create an object of mongoose model. Mongo generates an unique _id for that particular document before saving it on database. In fact it doesn’t care whether application is connected with database or not. Unlike relational databases, the _id of document is created by mongo driver not by database under the hood. If database gets many requests at a single time to save documents, so there is no need to wait for generating an unique ID to save document. This makes mongo db highly scalable and more faster than other databases. If you are thin...

How Mongo create unique Id for a document/object?

Image
You have noticed when you store a document in mongo db. Mongo sets the  _id property by itself with value of long string like this ….  5dbc11af4c23283312490b5c This _id has 24 characters and every 2 characters represent 1 byte. Essentially mongo creates 12 bytes unique identity for every document. This 12 bytes string is a group of 4 different identifiers. First 4 bytes  :- first 4 bytes represents time stamp. This stamp is the time when the document is created. Second 3 bytes  :- This suite represents machine identifier. Every different machine will have different machine identifier. Third 2 bytes  :- This suite represents process identifier. If you generate two different documents on same machine but on different processor. So, the process identifier will be different for both documents. Fourth 3 bytes  :- This suite represents auto increment counter. If we are on same machine, same processor and generate two different documen...