<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MongoDB Archives - LinuxTuto</title>
	<atom:link href="https://www.linuxtuto.com/tag/mongodb/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.linuxtuto.com/tag/mongodb/</link>
	<description>Linux Sysadmin and DevOps blog</description>
	<lastBuildDate>Mon, 04 Apr 2022 12:43:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://www.linuxtuto.com/wp-content/uploads/2022/01/cropped-LT_faveicon-32x32.png</url>
	<title>MongoDB Archives - LinuxTuto</title>
	<link>https://www.linuxtuto.com/tag/mongodb/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">201456972</site>	<item>
		<title>How to Install MongoDB 5 on Debian 11</title>
		<link>https://www.linuxtuto.com/how-to-install-mongodb-5-on-debian-11/</link>
					<comments>https://www.linuxtuto.com/how-to-install-mongodb-5-on-debian-11/#comments</comments>
		
		<dc:creator><![CDATA[LinuxTuto]]></dc:creator>
		<pubDate>Mon, 04 Apr 2022 12:43:42 +0000</pubDate>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[MongoDB]]></category>
		<guid isPermaLink="false">https://www.linuxtuto.com/?p=316</guid>

					<description><![CDATA[<p>MongoDB is an open-source document database used in many modern web applications. It is classified as a NoSQL database. Unlike relational databases which store data...</p>
<p>The post <a href="https://www.linuxtuto.com/how-to-install-mongodb-5-on-debian-11/">How to Install MongoDB 5 on Debian 11</a> appeared first on <a href="https://www.linuxtuto.com">LinuxTuto</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>MongoDB is an open-source document database used in many modern web applications. It is classified as a NoSQL database. Unlike <a href="https://www.linuxtuto.com/how-to-install-mariadb-10-7-on-debian-11/">relational databases</a> which store data in tables according to a rigid schema, MongoDB stores data in documents with flexible schema. Applications can then retrieve this information in a JSON format.</p>
<h2><span class="has-inline-color has-vivid-purple-color">Update Operating System</span></h2>
<p>Update your <strong>Debian 11</strong> operating system to make sure all existing packages are up to date:</p>
<pre><code>$ sudo apt update &amp;&amp; sudo apt upgrade -y</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Install Dependencies</span></h2>
<p>Install the required packages for the installation with the following command:</p>
<pre><code>$ sudo apt install curl apt-transport-https software-properties-common ca-certificates dirmngr gnupg2</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Import MongoDB GPG Key</span></h2>
<p>We first need to import MongDB public GPG key as below:</p>
<pre><code>$ wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo  apt-key add -</code></pre>
<p>The output of the executed command should be “OK”.</p>
<h2><span class="has-inline-color has-vivid-purple-color">Add MongoDB 5.0 Repository</span></h2>
<p>MongoDB 5.0 packages are not available to install directly from the base repository of Debian 11 and we need to <a href="http://repo.mongodb.org/apt/debian">add the official one offered by the developers</a> of this NoSQL database:</p>
<pre><code>echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list</code></pre>
<p>Update the repository:</p>
<pre><code>$ sudo apt update</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Install MongoDB on Debian 11</span></h2>
<p>Now we will Install MongoDB with the following command:</p>
<pre><code>$ sudo apt-get install -y mongodb-org</code></pre>
<p>By default, MongoDB service is not started. Start the MongoDB service:</p>
<pre><code>$ sudo systemctl start mongod</code></pre>
<p>Confirm that MongoDB is actually running:</p>
<pre><code>$ sudo systemctl status mongod</code></pre>
<p>Output:</p>
<pre><code><span style="color: #00ff00;">●</span> mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: <span style="color: #00ff00;">active (running)</span> since Sun 2022-04-03 08:02:06 EDT; 9s ago
Docs: https://docs.mongodb.org/manual
Main PID: 6197 (mongod)
Memory: 66.4M
CPU: 974ms
CGroup: /system.slice/mongod.service
└─6197 /usr/bin/mongod --config /etc/mongod.conf

Apr 03 08:02:06 debian systemd[1]: Started MongoDB Database Server.</code></pre>
<p>To check the version of MongoDB which is installed.</p>
<pre><code>$ sudo mongod <span class="re5">--version</span></code></pre>
<pre><code> version v5.0.6
Build Info: {
    "version": "5.0.6",
    "gitVersion": "212a8dbb47f07427dae194a9c75baec1d81d9259",
    "openSSLVersion": "OpenSSL 1.1.1k  25 Mar 2021",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "debian10",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
</code></pre>
<p>Let us enable it to start on boot using this command:</p>
<pre><code>$ sudo systemctl enable mongod</code></pre>
<p>As needed, you can stop the <code>mongod</code> process by run the following command:</p>
<pre><code>$ sudo systemctl stop mongod</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Configure MongoDB</span></h2>
<p>By default, the configuration file for MongoDB is located at “<code>/etc/mongod.conf</code>”.</p>
<h3><span class="has-inline-color has-vivid-purple-color">Enable password authentication</span></h3>
<p>To enable password authentication open the configuration file:</p>
<pre><code>$ sudo nano /etc/mongod.conf</code></pre>
<p>Find the line <code>#security</code> and uncomment it (remove the #) and add “<strong><code>authorization: enabled</code></strong>”:</p>
<pre><code>security:
  authorization: enabled</code></pre>
<p>After that restart the <code>mongod</code> service for the changes to take effect:</p>
<pre><code>$ sudo systemctl restart mongod</code></pre>
<h3><span class="has-inline-color has-vivid-purple-color">Enable remote access</span></h3>
<p>To enable remote access to your MongoDB database, you need to edit the configuration file at “<code>/etc/mongod.conf</code>”.</p>
<pre><code>$ sudo nano /etc/mongod.conf</code></pre>
<pre><code># network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,your-server-IP</code></pre>
<p>After you’ve added the IP, restart the service:</p>
<pre><code>$ sudo systemctl restart mongod</code></pre>
<p>You also need to allow on the firewall the trusted remote IP addresses if you have enabled your firewall:</p>
<pre><code>$ sudo ufw allow from your-server-ip to any port 27017</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Creating Administrative MongoDB User</span></h2>
<p>If you enabled the MongoDB authentication, you’ll need to create an administrative user that can access and manage the MongoDB instance.</p>
<p>To access MongoDB shell, run the command <strong><code>mongosh</code></strong> on the terminal as shown:</p>
<pre><code>$ mongosh</code></pre>
<p>List existing databases:</p>
<pre><code>show dbs
admin 41 kB
config 36.9 kB
local 41 kB</code></pre>
<p>Connect to the admin database:</p>
<pre><code>use admin</code></pre>
<p>Create a admin user which will be used to manage the MongoDB:</p>
<pre><code>db.createUser(
   {
     user: "admin",
     pwd: "CR7yT5cfgB",
     roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
   }
 )</code></pre>
<p>Exit the mongo shell.</p>
<pre><code>exit</code></pre>
<p>Try to connect to MongoDB using a admin user you have previously created:</p>
<pre><code>$ sudo mongosh -u admin -p --authenticationDatabase admin</code></pre>
<p>You can try to connect to MongoDB by typing <code>mongosh</code> without any arguments.</p>
<p>Once connected, you can execute <code>show dbs</code> command. You will get error:</p>
<pre><code><span style="color: #993300;">MongoServerError</span>: command listDatabases requires authentication</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Uninstall MongoDB</span></h2>
<p>If you want to completely remove MongoDB and related dependencies, run the following command:</p>
<pre><code>$ sudo apt purge --autoremove -y mongodb-org</code></pre>
<p>You can also remove MongoDB logs, data, and other related directories and files:</p>
<pre><code>$ sudo rm -rf /var/log/mongodb
$ sudo rm -rf /var/lib/mongodb
$ sudo rm -rf ~/.mongodb
$ sudo rm -rf ~/.dbshell
$ sudo rm -rf ~/.mongorc.js</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Comments and Conclusion</span></h2>
<p>That’s it. You have successfully installed MongoDB 5.0 on Debian 11.</p>
<p>If you have any questions please leave a comment below.</p>
<p>The post <a href="https://www.linuxtuto.com/how-to-install-mongodb-5-on-debian-11/">How to Install MongoDB 5 on Debian 11</a> appeared first on <a href="https://www.linuxtuto.com">LinuxTuto</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.linuxtuto.com/how-to-install-mongodb-5-on-debian-11/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">316</post-id>	</item>
	</channel>
</rss>
