{"id":5025,"date":"2020-09-23T11:23:25","date_gmt":"2020-09-23T11:23:25","guid":{"rendered":"https:\/\/blog.verbat.com\/?p=2467"},"modified":"2024-05-22T07:14:12","modified_gmt":"2024-05-22T07:14:12","slug":"demystifying-mongodb","status":"publish","type":"post","link":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/","title":{"rendered":"Demystifying MongoDB"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Database are at the core of almost all internet and <strong><a href=\"https:\/\/www.verbat.com\/services\/enterprise-application-services\">enterprise applications<\/a><\/strong>. The need for scale and <strong><a href=\"https:\/\/www.verbat.com\/software-development\">faster application development<\/a><\/strong> has brought in a new generation of databases loosely termed as NoSQL databases. These are in non-tabular format and save data in a different format compared to relational database whereas relational database saves data in rows and columns organized into tables or sheets.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">Often developers encounter certain conceptual and technical difficulties with relational database when it is served with an application or multiple applications written in an object-oriented programming language or style. This is because a typical application objects must be mapped onto tables. But a typical application object is rarely related to a single table. This misalignment of application layer objects to tables and rows is called an Impedance Mismatch.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Impedance Mismatch<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\/\/ your application code<\/strong><br> <strong>class Foo {int x; string [] tags;} <\/strong> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the above example, you can see that the object Foo has an integer x and a string of tags. To match Foo to a relational database you need three tables, one for the main object, another for the tags and a third to relate them together.&nbsp;  <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png\" alt=\"\" class=\"wp-image-2468\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">To translate between the object in memory and\nwhat is saved in the database as an application developer you are forced to\ndevelop a mapping layer or use an ORM (Object Relational Mapper). Most of the\ntime objects don\u2019t translate to tables and rows. To top it off we may have to\nuse polymorphism or inheritance. Mapping these on to a relational database can\nadd a lot of complexity to the application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MongoDB adopts an entirely different\napproach. There is no schema to define, no tables and no relationships between\ncollections of objects. MongoDB allows you to structure data in a way that is\nefficient for computers to process and natural and easy for humans to read.\nEach document you save can be simple or complex as your application demands.\nThis also means that they can adapt or add data when they need without worrying\nthat this minor change would break everything.&nbsp;\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, MongoDB differs fundamentally from legacy databases because it can coordinate multiple servers to store data.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_50_49_196Z.png\" alt=\"\" class=\"wp-image-2469\"\/><\/figure>\n<\/div>\n\n\n<h4 class=\"wp-block-heading\">Scalability Issues<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Relational model requires a relational database engine for itself to manage writes in a special way. To ensure consistency as well as atomicity, it must lock rows and tables and permit only one writer access at a time.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_50_40_415Z.png\" alt=\"\" class=\"wp-image-2470\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Ensuring referential integrity across\nthe tables and rows increases the time the lock has to be in force. Higher\nlocking time implies less writes and updates per second resulting in higher\nlatency in transactions and thus slower application. Scaling out by replicating\nor sharding data to other server can make matters even complicated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If relational engines try to impose\nconsistency and extend these locks across networks, lock times can increase and\ntransactions latency even higher. This obviously results in a slower\napplication. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Relational database addresses such\nissues by deformalizing tables or by relaxing consistency for\ninstance by allowing dirty reads. But this undermines the purpose behind a\nrelational database. These methods are often used by production systems for\nreporting or decision support system database where there is a tolerance for a\ncertain margin of error. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-text-align-center is-style-large is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>\u201cSo how does MongoDB approach these issues\u201d<\/strong><\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, in MongoDB data is stored in the documents and there are no schema or tables, no rows, and columns and certainly no relationship between tables. The document is grouped into collections. A collection is like a table from a relational database. Although the document lives within a collection updating the document occurs one at a time. This implies that the there are no locking or enforcing of relationships nor constraints and no schema to protect.<\/li>\n\n\n\n<li>Two, in replications scenarios, replica sets provide redundancy and high availability with the consistency you choose. A replica set contains several data bearing nodes and optionally one arbiter node of which one and only one member is considered the primary node, while the other nodes are considered secondary nodes.  Also, there are no locks from the primary to the secondary. Mongo makes it easy to configure your application for higher latency and lesser consistency or vice versa. With multiple data copies on different database servers, replication provides also provides a level of fault tolerance against the loss of a single database server.<\/li>\n\n\n\n<li>Three, Mongo also has a feature called the capped collections. Capped collections have a fixed size and to make room for new documents, oldest documents in the collection are removed automatically without requiring scripts or explicit remove operations .The potential uses of capped collections include storing log information generated by high-volume systems.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_50_31_105Z.png\" alt=\"\" class=\"wp-image-2471\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">In short, it can be said that MongoDB is a cross-platform document-oriented database program designed for ease of development and scaling. The combination of document model and distributed systems components provide MongoDB with an advantage over relational database. With growing data volumes and performance requirements you can just add more servers instead of upgrading to million-dollar mainframe. It is also great for cloud environments where spreading load across several machines is by far the best way to scale.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.verbat.com\/\">it companies in dubai\u00a0<\/a>|\u00a0<a href=\"https:\/\/www.verbat.com\/software-development\">Software Development Companies in Dubai<\/a>\u00a0|\u00a0<a href=\"https:\/\/www.verbat.com\/search-engine-optimization\/search-engine-optimization-dubai\">SEO Companies in Dubai\u00a0|<\/a>\u00a0<a href=\"https:\/\/www.verbat.com\/technologies\/mobile-app-development\">mobile app development company uae<\/a>\u00a0|\u00a0<a href=\"https:\/\/www.verbat.com\/web-hosting\">Web Hosting Dubai<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Database are at the core of almost all internet and enterprise applications. The need for scale and faster application development has brought in a new generation of databases loosely termed as NoSQL databases. These are in non-tabular format and save data in a different format compared to relational database whereas relational database saves data in [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5025","post","type-post","status-publish","format-standard","hentry","category-others"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Demystifying MongoDB - Verbat<\/title>\n<meta name=\"description\" content=\"Uncover the essentials of MongoDB, from its key features and benefits to practical applications, in this comprehensive guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Demystifying MongoDB - Verbat\" \/>\n<meta property=\"og:description\" content=\"Uncover the essentials of MongoDB, from its key features and benefits to practical applications, in this comprehensive guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/\" \/>\n<meta property=\"og:site_name\" content=\"Software Development Company Dubai UAE - Verbat Technologies\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/verbatltd\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-23T11:23:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-22T07:14:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@verbatltd\" \/>\n<meta name=\"twitter:site\" content=\"@verbatltd\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Demystifying MongoDB\",\"datePublished\":\"2020-09-23T11:23:25+00:00\",\"dateModified\":\"2024-05-22T07:14:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/\"},\"wordCount\":873,\"publisher\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png\",\"articleSection\":[\"Others\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/\",\"url\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/\",\"name\":\"Demystifying MongoDB - Verbat\",\"isPartOf\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png\",\"datePublished\":\"2020-09-23T11:23:25+00:00\",\"dateModified\":\"2024-05-22T07:14:12+00:00\",\"description\":\"Uncover the essentials of MongoDB, from its key features and benefits to practical applications, in this comprehensive guide.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#primaryimage\",\"url\":\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png\",\"contentUrl\":\"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.verbat.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Demystifying MongoDB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.verbat.com\/blog\/#website\",\"url\":\"https:\/\/www.verbat.com\/blog\/\",\"name\":\"Verbat Technologies\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.verbat.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.verbat.com\/blog\/#organization\",\"name\":\"Verbat Technologies\",\"url\":\"https:\/\/www.verbat.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.verbat.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.verbat.com\/blog\/wp-content\/uploads\/2024\/04\/verbatltd_logo.jpg\",\"contentUrl\":\"https:\/\/www.verbat.com\/blog\/wp-content\/uploads\/2024\/04\/verbatltd_logo.jpg\",\"width\":200,\"height\":200,\"caption\":\"Verbat Technologies\"},\"image\":{\"@id\":\"https:\/\/www.verbat.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/verbatltd\",\"https:\/\/x.com\/verbatltd\",\"https:\/\/www.linkedin.com\/company\/verbatltd\"]},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Demystifying MongoDB - Verbat","description":"Uncover the essentials of MongoDB, from its key features and benefits to practical applications, in this comprehensive guide.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/","og_locale":"en_US","og_type":"article","og_title":"Demystifying MongoDB - Verbat","og_description":"Uncover the essentials of MongoDB, from its key features and benefits to practical applications, in this comprehensive guide.","og_url":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/","og_site_name":"Software Development Company Dubai UAE - Verbat Technologies","article_publisher":"https:\/\/www.facebook.com\/verbatltd","article_published_time":"2020-09-23T11:23:25+00:00","article_modified_time":"2024-05-22T07:14:12+00:00","og_image":[{"url":"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png"}],"twitter_card":"summary_large_image","twitter_creator":"@verbatltd","twitter_site":"@verbatltd","twitter_misc":{"Written by":"","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#article","isPartOf":{"@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/"},"author":{"name":"","@id":""},"headline":"Demystifying MongoDB","datePublished":"2020-09-23T11:23:25+00:00","dateModified":"2024-05-22T07:14:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/"},"wordCount":873,"publisher":{"@id":"https:\/\/www.verbat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png","articleSection":["Others"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/","url":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/","name":"Demystifying MongoDB - Verbat","isPartOf":{"@id":"https:\/\/www.verbat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#primaryimage"},"image":{"@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#primaryimage"},"thumbnailUrl":"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png","datePublished":"2020-09-23T11:23:25+00:00","dateModified":"2024-05-22T07:14:12+00:00","description":"Uncover the essentials of MongoDB, from its key features and benefits to practical applications, in this comprehensive guide.","breadcrumb":{"@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#primaryimage","url":"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png","contentUrl":"https:\/\/blog.verbat.com\/wp-content\/uploads\/2020\/09\/image_2020_09_23T10_51_15_981Z.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.verbat.com\/blog\/demystifying-mongodb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.verbat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Demystifying MongoDB"}]},{"@type":"WebSite","@id":"https:\/\/www.verbat.com\/blog\/#website","url":"https:\/\/www.verbat.com\/blog\/","name":"Verbat Technologies","description":"","publisher":{"@id":"https:\/\/www.verbat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.verbat.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.verbat.com\/blog\/#organization","name":"Verbat Technologies","url":"https:\/\/www.verbat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.verbat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.verbat.com\/blog\/wp-content\/uploads\/2024\/04\/verbatltd_logo.jpg","contentUrl":"https:\/\/www.verbat.com\/blog\/wp-content\/uploads\/2024\/04\/verbatltd_logo.jpg","width":200,"height":200,"caption":"Verbat Technologies"},"image":{"@id":"https:\/\/www.verbat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/verbatltd","https:\/\/x.com\/verbatltd","https:\/\/www.linkedin.com\/company\/verbatltd"]},{"@type":"Person","@id":""}]}},"_links":{"self":[{"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/posts\/5025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/comments?post=5025"}],"version-history":[{"count":1,"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/posts\/5025\/revisions"}],"predecessor-version":[{"id":5557,"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/posts\/5025\/revisions\/5557"}],"wp:attachment":[{"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/media?parent=5025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/categories?post=5025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.verbat.com\/blog\/wp-json\/wp\/v2\/tags?post=5025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}