{"id":121825,"date":"2022-07-29T13:44:45","date_gmt":"2022-07-29T10:44:45","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=121825"},"modified":"2024-10-11T09:43:06","modified_gmt":"2024-10-11T06:43:06","slug":"install-mongodb-6-on-debian","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/install-mongodb-6-on-debian\/","title":{"rendered":"How To Install MongoDB 6 on Debian 12\/11\/10"},"content":{"rendered":"\n<p><strong>NoSQL database<\/strong>&nbsp;is a database type where information is stored in JSON documents as opposed to rows and columns used in Relational databases. This technology was implemented in the 1970s when data storage was extremely expensive. In SQL databases, data is organized in rows and columns which make them extremely inflexible and difficult to modify. In NoSQL databases, developers are not tied to the rigid tabular approach and therefore are able to enjoy flexible schemas and scale easily with large amounts of data and high user loads.<\/p>\n\n\n\n<p>The most popular NoSQL databases are Apache Cassandra, ElasticSearch, Amazon DynamoDB, HBase, Couchbase, Redis, MongoDB e.t.c<\/p>\n\n\n\n<p><strong>MongoDB<\/strong> is a cross-platform, object-oriented NoSQL database developed by <strong><em>MongoDB Inc.<\/em><\/strong> licensed under the Server Side Public License. It is implemented in C++ language and supports both 32 and 64-bit systems. MongoDB is highly used in applications that require enormous scalability and flexibility.<\/p>\n\n\n\n<p>MongoDB provides high availability through a <strong><em>replica set<\/em><\/strong>. This is typically a group of <code>mongod<\/code> services that have the same data set. They provide high availability which is basic for all production deployments. In MongoDB replication, there are <em>data-bearing nodes<\/em> and optionally one<strong> arbiter node<\/strong>. In the data-bearing nodes group, only one is considered the <strong>Primary<\/strong> node and the others the secondary nodes. The primary node mainly receives all the write operations from the application. The secondary nodes replicate the primary node&#8217;s operation logs. The secondary nodes replicate data sets from the primary node. <\/p>\n\n\n\n<p>The image below can be used to understand the architecture:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"507\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/MongoDB-6-on-Debian-11.png\" alt=\"\" class=\"wp-image-121827\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/MongoDB-6-on-Debian-11.png 620w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/MongoDB-6-on-Debian-11-300x245.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/MongoDB-6-on-Debian-11-514x420.png 514w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/figure>\n\n\n\n<p>MongoDB is highly used in the following areas:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong style=\"color: initial\">Inventory and catalog management<\/strong><span style=\"color: initial\"> &#8211; NoSQL databases provide high availability and predictable, cost-effective, horizontal scalability. This makes MongoDB effective in e-commerce companies that have massive and rowing online catalogs.<\/span><\/li>\n\n\n\n<li><strong>E-commerce product catalog<\/strong> &#8211; organizations are able to build applications with improved customer satisfaction by providing a single view of the customer by aggregating customer and product information<\/li>\n\n\n\n<li><strong>Mobile and social networking sites<\/strong> &#8211; MongoDB is able to handle;e large volumes of data extremely fast.<\/li>\n\n\n\n<li><strong>Real-time analytics and high-speed logging<\/strong> &#8211; It is used in customer analytics, real-time data integration that requires large volumes of high-speed data logging and aggregation<\/li>\n\n\n\n<li><strong>Fraud detection and identity authentication<\/strong> &#8211; MongoDB is used to provide real-time analysis of a large volume to identify any abnormality<\/li>\n\n\n\n<li>Financial services and payments<\/li>\n\n\n\n<li>Content management systems<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Features of MongoDB 6.0<\/h2>\n\n\n\n<p>The latest release <strong><em>MongoDB 6.0 <\/em><\/strong>offers a lot of features that include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Improved support for event-driven architectures<\/strong> &#8211; MongoDB 6.0 enriches change streams, adding abilities that take change streams to the next level.<\/li>\n\n\n\n<li><strong>More operators, less work<\/strong> &#8211; The operators allow enable you to push more work to the database while spending less time writing code.<\/li>\n\n\n\n<li><strong>Deeper insights from enriched queries<\/strong> &#8211; users are able to process multiple documents and return computed results. This can help build complex data processing pipelines to extract the insights you need.<\/li>\n\n\n\n<li><strong>Data security and operational efficiency<\/strong> &#8211; It allows users to compress and encrypt audit events before being written to the disk, leveraging their own KMIP-compliant key management system. The log encryption protects event integrity and confidentiality.<\/li>\n\n\n\n<li><strong>Seamless data sync<\/strong> &#8211; The Cluster-to-Cluster Sync provides an easy way to migrate data to the cloud, with continuous, unidirectional data synchronization between two MongoDB clusters<\/li>\n\n\n\n<li><strong>More resilient operations<\/strong> &#8211; MongoDB\u2019s replica set design allows users to withstand and overcome outages. MongoDB 6.0 introduces improvements to sharding, the mechanism that enables horizontal scalability.<\/li>\n<\/ul>\n\n\n\n<p>This guide provides the required steps on how to install MongoDB 6 on Debian 11 \/ Debian 10<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System Requirements<\/h2>\n\n\n\n<p>To enable to install and run MongoDB, you need the following CPU architectures:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For <strong>x86_64<\/strong> microarchitecture:\n<ul class=\"wp-block-list\">\n<li>Intel x86_64 of a Sandy Bridge or later Core processor or a Tiger Lake or later Celeron or Pentium processor<\/li>\n\n\n\n<li>AMD x86_64 of a Bulldozer or later processor.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>ARM64<\/strong> microarchitecture\n<ul class=\"wp-block-list\">\n<li>ARMv8.2-A or later microarchitecture<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Check the architecture using the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">cat \/proc\/cpuinfo<\/mark>\nprocessor\t: 0\nvendor_id\t: GenuineIntel\ncpu family\t: 6\nmodel\t\t: 94\nmodel name\t: Intel(R) Xeon(R) CPU E3-1275 v5 @ 3.60GHz\nstepping\t: 3\nmicrocode\t: 0xf0\ncpu MHz\t\t: 3600.056\ncache size\t: 16384 KB\n.....<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Add MongoDB 6.0 Repository<\/h2>\n\n\n\n<p>MongoDB offers two major editions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Community edition<\/strong>: a free edition<\/li>\n\n\n\n<li><strong>Enterprise edition<\/strong>: provided as part of the Mongo Enterprise Advanced subscription. It offers advanced features such as on-disk encryption, Kerberos and LDAP support, auditing e.t.c.<\/li>\n<\/ul>\n\n\n\n<p>In this guide, we will install the Community Edition, but since it is not provided in the default repositories, we need to add the repositories to the system.<\/p>\n\n\n\n<p>Install the required tools:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install wget curl gnupg software-properties-common apt-transport-https ca-certificates lsb-release<\/code><\/pre>\n\n\n\n<p>First, import the GPG key<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -fsSL https:\/\/www.mongodb.org\/static\/pgp\/server-6.0.asc|sudo gpg --dearmor -o \/etc\/apt\/trusted.gpg.d\/mongodb-6.gpg<\/code><\/pre>\n\n\n\n<p>Now add the MongoDB 6.0 repository to the system.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">##On Debian 12<\/mark><\/em>\ncurl -fsSL https:\/\/www.mongodb.org\/static\/pgp\/server-7.0.asc|sudo gpg --dearmor -o \/etc\/apt\/trusted.gpg.d\/mongodb-7.gpg\necho \"deb http:\/\/repo.mongodb.org\/apt\/debian bookworm\/mongodb-org\/7.0 main\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-6.0.list\n\n<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">##On Debian 11\n<\/mark><\/em>echo \"deb http:\/\/repo.mongodb.org\/apt\/debian bullseye\/mongodb-org\/6.0 main\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-6.0.list\n\n<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">##On Debian 10\n<\/mark><\/em>echo \"deb http:\/\/repo.mongodb.org\/apt\/debian buster\/mongodb-org\/6.0 main\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-6.0.list<\/code><\/pre>\n\n\n\n<p>Once added, update the APT package index:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install MongoDB 6.0 Server<\/h2>\n\n\n\n<p>Once the repository has been added, MongoDB 6.0 can be installed with the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install mongodb-org<\/code><\/pre>\n\n\n\n<p>Dependency Tree:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The following additional packages will be installed:\n  mongodb-database-tools mongodb-mongosh mongodb-org-database\n  mongodb-org-database-tools-extra mongodb-org-mongos\n  mongodb-org-server mongodb-org-shell mongodb-org-tools\nThe following NEW packages will be installed:\n  mongodb-database-tools mongodb-mongosh mongodb-org\n  mongodb-org-database mongodb-org-database-tools-extra\n  mongodb-org-mongos mongodb-org-server mongodb-org-shell\n  mongodb-org-tools\n0 upgraded, 9 newly installed, 0 to remove and 39 not upgraded.\nNeed to get 134 MB of archives.\nAfter this operation, 458 MB of additional disk space will be used.\nDo you want to continue? &#91;Y\/n] <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">y<\/mark><\/code><\/pre>\n\n\n\n<p>You can also install a specific version for each component:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install -y mongodb-org=<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">&lt;version&gt;<\/mark><\/em> mongodb-org-database=<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">&lt;version&gt;<\/mark><\/em>  mongodb-org-server=<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">&lt;version&gt;<\/mark><\/em>  mongodb-org-shell=<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">&lt;version&gt;<\/mark><\/em>  mongodb-org-mongos=<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">&lt;version&gt;<\/mark><\/em>  mongodb-org-tools=<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">&lt;version&gt;<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>Once the installation is complete, start and enable the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable --now mongod<\/code><\/pre>\n\n\n\n<p>Verify that the service is running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">systemctl status mongod<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-light-green-cyan-color\">\u25cf <\/mark>mongod.service - MongoDB Database Server\n     Loaded: loaded (\/lib\/systemd\/system\/mongod.service; enabled; vendor preset: enabled)\n     Active: <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">active (running)<\/mark> since Tue 2023-08-29 00:46:04 UTC; 3s ago\n       Docs: https:\/\/docs.mongodb.org\/manual\n   Main PID: 2245 (mongod)\n     Memory: 72.9M\n        CPU: 774ms\n     CGroup: \/system.slice\/mongod.service\n             \u2514\u25002245 \/usr\/bin\/mongod --config \/etc\/mongod.conf\n\nAug 29 00:46:04 debian11 systemd&#91;1]: Started MongoDB Database Server.\nAug 29 00:46:04 debian11 mongod&#91;2245]: {\"t\":{\"$date\":\"2023-08-29T00:46:04.173Z\"},\"s\":\"I\",  \"c\":\"CONTROL\",  \"id\":7484500, \"ctx\":\"-\",\"msg\":\"Environment variable MONGODB_CONFIG_OVERRIDE_NOFORK == 1, o&gt;\nroot@debian11:~#<\/code><\/pre>\n\n\n\n<p>Check the available version of MongoDB:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">mongod --version<\/mark>\ndb version v6.0.9\nBuild Info: {\n    \"version\": \"6.0.9\",\n    \"gitVersion\": \"e61bf27c2f6a83fed36e5a13c008a32d563babe2\",\n    \"openSSLVersion\": \"OpenSSL 1.1.1n  15 Mar 2022\",\n    \"modules\": &#91;],\n    \"allocator\": \"tcmalloc\",\n    \"environment\": {\n        \"distmod\": \"debian11\",\n        \"distarch\": \"x86_64\",\n        \"target_arch\": \"x86_64\"\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configure MongoDB 6.0 Server<\/h2>\n\n\n\n<p>MongoDB stores its config file at&nbsp;<strong><em>\/etc\/mongod.conf<\/em><\/strong>. There are many configurations you can make in the file such as database path, logs path, listening port, address e.t.c. In this guide, we will make the below configs:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable Password Authentication<\/h3>\n\n\n\n<p>When installed, MongoDB does not offer password protection to the database. This can pose a security threat since anyone can access and use the database. To secure the instance, you need to create a user and set a password:<\/p>\n\n\n\n<p>Access the shell:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mongosh<\/code><\/pre>\n\n\n\n<p>Create the admin user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use admin\ndb.createUser(\n{\nuser: \"mongouser\",\npwd: passwordPrompt(), \/\/ or cleartext password\nroles: &#91; { role: \"userAdminAnyDatabase\", db: \"admin\" }, \"readWriteAnyDatabase\" ]\n}\n)<\/code><\/pre>\n\n\n\n<p>You will be required to provide a password for the user. Once set,&nbsp;<strong><em>exit<\/em><\/strong>&nbsp;the shell and enable authentication in the config file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/mongod.conf<\/code><\/pre>\n\n\n\n<p>Find and uncomment the&nbsp;<strong>security<\/strong>&nbsp;part and add the line as shown.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>security:\n    authorization: \"enabled\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Enable Remote Access<\/h3>\n\n\n\n<p>MongoDB listens on localhost by default, to change this and enable it to listen on the IP address, edit the config as shown:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># network interfaces\nnet:\n  port: 27017\n  bindIp: 0.0.0.0<\/code><\/pre>\n\n\n\n<p>Once the desired changes have been made, save the file and restart the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart mongod<\/code><\/pre>\n\n\n\n<p>If you have a firewall enabled, allow the port through it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 27017<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using MongoDB 6.0<\/h2>\n\n\n\n<p>Now access the MongoDB shell using the admin user and password created earlier.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">mongosh -u mongouser<\/mark>\nEnter password: *********\nConnecting to:\t\tmongodb:\/\/&lt;credentials&gt;@127.0.0.1:27017\/?directConnection=true&amp;serverSelectionTimeoutMS=2000&amp;appName=mongosh+1.5.3\nUsing MongoDB:\t\t6.0.0\nUsing Mongosh:\t\t1.5.3\n\nFor mongosh info see: https:\/\/docs.mongodb.com\/mongodb-shell\/\n\ntest&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create a Database MongoDB<\/h3>\n\n\n\n<p>First, list the available databases:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">show dbs<\/mark>\nadmin   132.00 KiB\nconfig   12.00 KiB\nlocal    72.00 KiB<\/code><\/pre>\n\n\n\n<p>To create a database in MongoDB, just switch to a non-existing database. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">use sampledb<\/mark>\nswitched to db sampledb<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create a collection in MongoDB<\/h3>\n\n\n\n<p>Collections are equivalent to tables in SQL databases. To create a table in MongoDB, use a command with the below syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>db.userdetails.insertOne(\n   {F_Name: \"<strong><em>Computing<\/em><\/strong>\",\n    L_NAME: \"<strong><em>ForGeeks<\/em><\/strong>\",\n    ID_NO: \"124345\",\n     AGE: \"49\",\n     TEL: \"25465467187\"\n   }\n)<\/code><\/pre>\n\n\n\n<p>Once created, list the available collections:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">show collections<\/mark>\nuserdetails<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create an overall admin<\/h3>\n\n\n\n<p>An overall admin has the ability to access and use any database. For example, the user created earlier was an overall admin. To create another admin user, use the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use admin\ndb.createUser(\n  {\n    user: '<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">admin<\/mark><\/em>',\n    pwd: '<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">AdminPassW0rd<\/mark><\/em>',\n    roles: &#91; { role: 'userAdminAnyDatabase', db: 'admin' } ]\n  }\n);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create an admin for a specific database<\/h3>\n\n\n\n<p>You can create an admin user for a specific database. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use testdatabase\ndb.createUser(\n  {\n    user: '<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">testadmin<\/mark><\/em>',\n    pwd: '<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">TestPassW0rd<\/mark><\/em>',\n    roles: &#91; { role: 'userAdmin', db: 'testdatabase' } ]\n  }\n);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create a User with Read and Write privileges<\/h3>\n\n\n\n<p>It is also possible to create a user with read and write permissions to a specific database. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use testdatabase\ndb.createUser(\n   {\n     user: '<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-cyan-blue-color\">testuser<\/mark>',\n     pwd: '<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">TestPassW0rd<\/mark><\/em>',\n     roles: &#91; { role: 'readWrite', db: 'testdatabase' } ]\n   }\n );<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">List Users on MongoDB<\/h3>\n\n\n\n<p>To list the available users, query the&nbsp;<strong><em>system.users<\/em><\/strong>&nbsp;collection.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use admin\ndb.system.users.find()<\/code><\/pre>\n\n\n\n<p>Sample Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"623\" height=\"869\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/MongoDB-6-on-Debian.png\" alt=\"\" class=\"wp-image-121829\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/MongoDB-6-on-Debian.png 623w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/MongoDB-6-on-Debian-215x300.png 215w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2022\/07\/MongoDB-6-on-Debian-301x420.png 301w\" sizes=\"auto, (max-width: 623px) 100vw, 623px\" \/><\/figure>\n\n\n\n<p>Exit the shell using the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; exit<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using a Custom Data Path in MongoDB<\/h2>\n\n\n\n<p>Normally, MongoDB stores its data in&nbsp;<strong><em>\/var\/lib\/mongodb<\/em><\/strong>. However, this can be changed to another preferred data path. To achieve this, begin by stopping the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl stop mongod.service<\/code><\/pre>\n\n\n\n<p>Create the custom data path with the correct permissions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/data\/mongo\nsudo chown -R mongodb:mongodb \/data\/mongo<\/code><\/pre>\n\n\n\n<p>Proceed and copy the contents of the old directory to this new path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo cp -r \/var\/lib\/mongodb\/* \/data\/mongo<\/code><\/pre>\n\n\n\n<p>You can move the old directory to a backup file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mv \/var\/lib\/mongodb \/var\/lib\/mongodb.bak<\/code><\/pre>\n\n\n\n<p>Now edit the config file to accommodate the new path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/mongod.conf<\/code><\/pre>\n\n\n\n<p>Make the below changes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Where and how to store data.\nstorage:\n  dbPath: <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">\/data\/mongo<\/mark>\n.......<\/code><\/pre>\n\n\n\n<p>Save the file, reload the daemon and start the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload\nsudo systemctl start mongod<\/code><\/pre>\n\n\n\n<p>Verify if the service is running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">systemctl status mongod<\/mark>\n\u25cf mongod.service - MongoDB Database Server\n     Loaded: loaded (\/lib\/systemd\/system\/mongod.service; enabled; vendor preset: enabled)\n     Active: <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">active (running)<\/mark> since Thu 2022-07-28 16:36:02 EDT; 3s ago\n       Docs: https:\/\/docs.mongodb.org\/manual\n   Main PID: 2020 (mongod)\n     Memory: 164.3M\n        CPU: 737ms\n     CGroup: \/system.slice\/mongod.service\n             \u2514\u25002020 \/usr\/bin\/mongod --config \/etc\/mongod.conf<\/code><\/pre>\n\n\n\n<p>Voila!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this guide, we have installed MongoDB 6 on Debian 11 \/ Debian 10. In addition to that, we have learned how to configure MongoDB, and create users, databases, and collections.<\/p>\n\n\n\n<p>Interested in more?<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/computingforgeeks.com\/how-to-install-mongodb-on-debian-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">How To Install MongoDB 5.0 on Debian<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/how-to-install-mongodb-database-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">How To Install MongoDB 5.0 on Ubuntu<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/install-mongodb-compass-on-rocky-linux-centos\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install MongoDB Compass on CentOS &amp; Rocky Linux 8<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>NoSQL database&nbsp;is a database type where information is stored in JSON documents as opposed to rows and columns used in Relational databases. This technology was implemented in the 1970s when data storage was extremely expensive. In SQL databases, data is organized in rows and columns which make them extremely inflexible and difficult to modify. In &#8230; <a title=\"How To Install MongoDB 6 on Debian 12\/11\/10\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/install-mongodb-6-on-debian\/\" aria-label=\"Read more about How To Install MongoDB 6 on Debian 12\/11\/10\">Read more<\/a><\/p>\n","protected":false},"author":21,"featured_media":121827,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[461,26,299,50],"tags":[37664],"class_list":["post-121825","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-databases","category-debian","category-how-to","category-linux-tutorials","tag-mongodb-6-on-debian"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/121825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=121825"}],"version-history":[{"count":1,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/121825\/revisions"}],"predecessor-version":[{"id":159116,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/121825\/revisions\/159116"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/121827"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=121825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=121825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=121825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}