all repos — gemini-redirect @ 69f17cbf52b3d5a22fa674bb38133feacfeab00a

blog/ribw/mongodb-an-introduction/index.html (view raw)

 1<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=description content="Official Lonami's website"><meta name=viewport content="width=device-width, initial-scale=1.0, user-scalable=yes"><title> MongoDB: an Introduction | Lonami's Blog </title><link rel=stylesheet href=/style.css><body><article><nav class=sections><ul class=left><li><a href=/>lonami's site</a><li><a href=/blog class=selected>blog</a><li><a href=/golb>golb</a></ul><div class=right><a href=https://github.com/LonamiWebs><img src=/img/github.svg alt=github></a><a href=/blog/atom.xml><img src=/img/rss.svg alt=rss></a></div></nav><main><h1 class=title>MongoDB: an Introduction</h1><div class=time><p>2020-03-05T01:00:06+00:00<p>last updated 2020-04-08T17:38:22+00:00</div><p>This is the first post in the MongoDB series, where we will introduce the MongoDB database system and take a look at its features and installation methods.<p>Other posts in this series:<ul><li><a href=/blog/ribw/mongodb-an-introduction/>MongoDB: an Introduction</a> (this post)<li><a href=/blog/ribw/mongodb-basic-operations-and-architecture/>MongoDB: Basic Operations and Architecture</a><li><a href=/blog/ribw/developing-a-python-application-for-mongodb/>Developing a Python application for MongoDB</a></ul><p>This post is co-authored wih Classmate.<hr><p><img src=https://lonami.dev/blog/ribw/mongodb-an-introduction/mongodb.png alt="NoSQL database – MongoDB – First delivery"><h2 id=purpose-of-technology>Purpose of technology</h2><p>MongoDB is a <strong>general purpose, document-based, distributed database</strong> built for modern application developers and for the cloud era, with the scalability and flexibility that you want with the querying and indexing that you need. It being a document database means it stores data in JSON-like documents.<p>The Mongo team believes this is the most natural way to think about data, which is (they claim) much more expressive and powerful than the traditional row/column model, since programmers think in objects.<h2 id=how-it-works>How it works</h2><p>MongoDB’s architecture can be summarized as follows:<ul><li>Document data model.<li>Distributed systems design.<li>Unified experience with freedom to run it anywhere.</ul><p>For a more in-depth explanation, MongoDB offers a <a href=https://www.mongodb.com/collateral/mongodb-architecture-guide>download to the MongoDB Architecture Guide</a> with roughly ten pages worth of text.<p><img src=https://lonami.dev/blog/ribw/mongodb-an-introduction/knGHenfTGA4kzJb1PHmS9EQvtZl2QlhbIPN15M38m8fZfZf7ODwYfhf0Tltr.png> _ Overview of MongoDB’s architecture_<p>Regarding usage, MongoDB comes with a really nice introduction along with JavaScript, Python, Java, C++ or C# code at our choice, which describes the steps necessary to make it work. Below we will describe a common workflow.<p>First, we must <strong>connect</strong> to a running MongoDB instance. Once the connection succeeds, we can access individual «collections», which we can think of as <em>tables</em> where collections of data is stored.<p>For instance, we could <strong>insert</strong> an arbitrary JSON document into the <code>restaurants</code> collection to store information about a restaurant.<p>At any other point in time, we can <strong>query</strong> these collections. The queries range from trivial, empty ones (which would retrieve all the documents and fields) to more rich and complex queries (for instance, using AND and OR operators, checking if data exists, and then looking for a value in a list).<p>MongoDB also supports the creation of <strong>indices</strong>, similar to those in other database systems. It allows for the creation of indices on any field or subfields.<p>In Mongo, the <strong>aggregation pipeline</strong> allows us to filter and analyze data based on a given set of criteria. For example, we could pull all the documents in the <code>restaurants</code> collection that have a <code>category</code> of <code>Bakery</code> using the <code>$match</code> operator. Then, we can group them by their star rating using the <code>$group</code> operator. Using the accumulator operator, <code>$sum</code>, we can see how many bakeries in our collection have each star rating.<h2 id=features>Features</h2><p>The features can be seen all over the place in their site, because it’s something they make a lot of emphasis on:<ul><li><p><strong>Easy development</strong>, thanks to the document data model, something they claim to be «the best way to work with data».<li><p>Data is stored in flexible JSON-like documents.<li><p>This model directly maps to the objects in the application’s code.<li><p>Ad hoc queries, indexing, and real time aggregation provide powerful ways to access and analyze the data.<li><p><strong>Powerful query language</strong>, with a rich and expressive query language that allows filtering and sorting by any field, no matter how nested it may be within a document. The queries are themselves JSON, and thus easily composable.<li><p><strong>Support for aggregations</strong> and other modern use-cases such as geo-based search, graph search, and text search.<li><p><strong>A distributed systems design</strong>, which allows developers to intelligently put data where they want it. High availability, horizontal scaling, and geographic distribution are built in and easy to use.<li><p><strong>A unified experience</strong> with the freedom to run anywhere, which allows developers to future-proof their work and eliminate vendor lock-in.</ul><h2 id=corner-in-cap-theorem>Corner in CAP theorem</h2><p>MongoDB’s position in the CAP theorem (Consistency, Availability, Partition Tolerance) depends on the database and driver configurations, and the type of disaster.<ul><li>With <strong>no partitions</strong>, the main focus is <strong>CA</strong>.<li>If there are **partitions **but the system is <strong>strongly connected</strong>, the main focus is <strong>AP</strong>: non-synchronized writes from the old primary are ignored.<li>If there are <strong>partitions</strong> but the system is <strong>not strongly connected</strong>, the main focus is <strong>CP</strong>: only read access is provided to avoid inconsistencies. The general consensus seems to be that Mongo is <strong>CP</strong>.</ul><h2 id=download>Download</h2><p>We will be using the apt-based installation.<p>The Community version can be downloaded by anyone through <a href=https://www.mongodb.com/download-center/community>MongoDB Download Center</a>, where one can choose the version, Operating System and Package.MongoDB also seems to be <a href=https://packages.ubuntu.com/eoan/mongodb>available in Ubuntu’s PPAs</a>.<h2 id=installation>Installation</h2><p>We will be using an Ubuntu-based system, with apt available. To install MongoDB, we open a terminal and run the following command:<pre><code>apt install mongodb
 2</code></pre><p>After confirming that we do indeed want to install the package, we should be able to run the following command to verify that the installation was successful:<pre><code>mongod --version
 3</code></pre><p>The output should be similar to the following:<pre><code>db version v4.0.16
 4git version: 2a5433168a53044cb6b4fa8083e4cfd7ba142221
 5OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
 6allocator: tcmalloc
 7modules: none
 8build environment:
 9	distmod: ubuntu1804
10	distarch: x86_64
11	target_arch: x86_64
12</code></pre><h2 id=references>References</h2><ul><li><a href=https://www.mongodb.com/>MongoDB’s official site</a><li><a href=https://www.mongodb.com/what-is-mongodb>What is MongoDB?</a><li><a href=https://www.mongodb.com/mongodb-architecture>MongoDB Architecture</a><li><a href=https://stackoverflow.com/q/11292215/4759433>Where does mongodb stand in the CAP theorem?</a><li><a href=https://medium.com/@bikas.katwal10/mongodb-vs-cassandra-vs-rdbms-where-do-they-stand-in-the-cap-theorem-1bae779a7a15>What is the CAP Theorem? MongoDB vs Cassandra vs RDBMS, where do they stand in the CAP theorem?</a><li><a href=https://www.quora.com/Why-doesnt-MongoDB-have-availability-in-the-CAP-theorem>Why doesn’t MongoDB have availability in the CAP theorem?</a><li><a href=https://docs.mongodb.com/manual/installation/>Install MongoDB</a></ul></main><footer><div><p>Share your thoughts, or simply come hang with me <a href=https://t.me/LonamiWebs><img src=/img/telegram.svg alt=Telegram></a> <a href=mailto:totufals@hotmail.com><img src=/img/mail.svg alt=Mail></a></div></footer></article><p class=abyss>Glaze into the abyss… Oh hi there!