<?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>Archives des NoSQL - dbi Blog</title>
	<atom:link href="https://www.dbi-services.com/blog/category/nosql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbi-services.com/blog/category/nosql/</link>
	<description></description>
	<lastBuildDate>Sun, 26 Jul 2026 15:18:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/cropped-favicon_512x512px-min-32x32.png</url>
	<title>Archives des NoSQL - dbi Blog</title>
	<link>https://www.dbi-services.com/blog/category/nosql/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MongoDB DMK 2.5.0: Sharding support and new features</title>
		<link>https://www.dbi-services.com/blog/mongodb-dmk-2-5-0-sharding-support-and-new-features/</link>
					<comments>https://www.dbi-services.com/blog/mongodb-dmk-2-5-0-sharding-support-and-new-features/#respond</comments>
		
		<dc:creator><![CDATA[Julien Delattre]]></dc:creator>
		<pubDate>Fri, 26 Jun 2026 12:54:00 +0000</pubDate>
				<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[2.5.0]]></category>
		<category><![CDATA[DMK]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Mongo]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[New]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[Sharding]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=45326</guid>

					<description><![CDATA[<p>In this blog, I will present the new features introduced with the latest release (2.5.0) of the MongoDB DMK. The DMK is a set of standardized tools that aims at easing the work of DBAs by having dbi&#8217;s best practices embedded in common scripts across all the database servers of an organization. dbi services provides [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-dmk-2-5-0-sharding-support-and-new-features/">MongoDB DMK 2.5.0: Sharding support and new features</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this blog, I will present the new features introduced with the latest release (<strong>2.5.0</strong>) of the MongoDB DMK.</p>



<p class="wp-block-paragraph">The DMK is a set of standardized tools that aims at easing the work of DBAs by having dbi&#8217;s best practices embedded in common scripts across all the database servers of an organization.</p>



<p class="wp-block-paragraph">dbi services provides the&nbsp;<a href="https://www.dbi-services.com/fr/produits/dmk-management-kit/" target="_blank" rel="noreferrer noopener">DMK</a>&nbsp;(<em>Database Management Kit</em>) to its customers for multiple technologies: Oracle, Postgres, MongoDB, etc. This toolkit is provided&nbsp;<strong>free of charge</strong>&nbsp;to all clients who work with dbi services on a consulting project.</p>



<h2 id="h-new-features-of-the-mongodb-dmk-in-2-5-0" class="wp-block-heading">New features of the MongoDB DMK in 2.5.0</h2>



<h3 id="h-sharding-support" class="wp-block-heading">Sharding support</h3>



<p class="wp-block-paragraph">The biggest addition in DMK 2.5.0 is&nbsp;<strong>full sharding support</strong>. DMK can now create, start, stop, restart, and display the status of every component of a sharded MongoDB cluster: config server replica sets, shard replica sets, and&nbsp;<code>mongos</code>&nbsp;routers.</p>



<p class="wp-block-paragraph">Internally, <strong>instance management was refactored</strong> into a class hierarchy: a <code>MongoInstance</code> base class handles what is common to all MongoDB processes (URI construction, <code>mongosh</code> command execution, status gathering), and <code>MongodInstance</code> / <code>MongosInstance</code> extend it for their respective types. From a day-to-day usage perspective, this is transparent: you use the same <code>dmk_db_ctl.py</code> and <code>dmk_status.py</code> commands for all instance types.</p>



<p class="wp-block-paragraph">A few behaviours are specific to&nbsp;<code>mongos</code>: stopping a&nbsp;<code>mongos</code>&nbsp;router uses&nbsp;<code>SIGTERM</code>&nbsp;instead of the&nbsp;<code>--shutdown</code>&nbsp;command (which&nbsp;<code>mongos</code>&nbsp;does not support), and trying to back up a&nbsp;<code>mongos</code>&nbsp;instance now raises an explicit error, since&nbsp;<code>mongos</code>&nbsp;processes hold no data. In a sharded configuration, the underlying shards should be backed up instead.</p>



<p class="wp-block-paragraph"><strong>New configuration templates</strong> for each sharding component type are available in <code>$DMK_HOME/templates/dbcreate/</code>, in both forked (no systemd) and non-forked (systemd-managed) variants. A dedicated systemd unit file template (<code>mongos.service.template</code>) was also added for <code>mongos</code> routers.</p>



<p class="wp-block-paragraph">Three new generic JavaScript scripts in&nbsp;<code>$DMK_HOME/js/</code>&nbsp;handle the initialization steps:</p>



<ul class="wp-block-list">
<li><code>csrs_initiate.js</code> — initiate a config server replica set</li>



<li><code>rs_initiate.js</code> (updated) — initiate a shard or standalone replica set, now with optional arbiter support</li>



<li><code>sh_addshards.js</code> — register shards in the cluster via a <code>mongos</code> router</li>
</ul>



<p class="wp-block-paragraph">All three receive their parameters via the&nbsp;<code>mongosh</code>&nbsp;<code>--eval</code>&nbsp;flag, keeping them reusable across any cluster topology:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
# Initiate the config server replica set
mongosh 127.0.0.1:27017 \
  --eval &quot;var rsName=&#039;csrs&#039;; var rsHosts=&#x5B;&#039;127.0.0.1:27017&#039;,&#039;127.0.0.1:27018&#039;,&#039;127.0.0.1:27019&#039;];&quot; \
  $DMK_HOME/js/csrs_initiate.js

# Initiate shard 1 with an arbiter
mongosh 127.0.0.1:27020 \
  --eval &quot;var rsName=&#039;rs1&#039;; var rsHosts=&#x5B;&#039;127.0.0.1:27020&#039;,&#039;127.0.0.1:27021&#039;]; var arbiterHost=&#039;127.0.0.1:27022&#039;;&quot; \
  $DMK_HOME/js/rs_initiate.js

# Add all shards from a mongos router
mongosh 127.0.0.1:27030 \
  --eval &quot;var shards=&#x5B;&#039;rs1/127.0.0.1:27020,127.0.0.1:27021&#039;,&#039;rs2/127.0.0.1:27023,127.0.0.1:27024&#039;,&#039;rs3/127.0.0.1:27026,127.0.0.1:27027&#039;];&quot; \
  $DMK_HOME/js/sh_addshards.js
</pre></div>


<h3 id="h-new-nbsp-check-status-nbsp-option-in-nbsp-dmk-db-ctl-py" class="wp-block-heading">New&nbsp;<code>--check-status</code>&nbsp;option in&nbsp;<code>dmk_db_ctl.py</code></h3>



<p class="wp-block-paragraph">The&nbsp;<code>dmk_db_ctl.py</code>&nbsp;script now accepts a&nbsp;<code>--check-status</code>&nbsp;flag. When provided, it polls the instance after the start, stop, or restart command to confirm the instance has reached the expected state. This was the default behaviour until now, which led to unwanted errors when setting up DMK.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
dmk_db_ctl.py -i mdb01 -a start --check-status
dmk_db_ctl.py -i mdb01 -a stop --check-status
dmk_db_ctl.py -i mdb01 -a restart --check-status
</pre></div>


<p class="wp-block-paragraph">Without this flag, the script returns immediately after issuing the command. It should be noted that when using the&nbsp;<code>restart</code>&nbsp;option, the status will be checked after stopping the instance. Otherwise, if the instance is still running when the start was issued, the restart could silently succeed without actually restarting anything.</p>



<h3 id="h-changes-made-to-nbsp-dmk-status-py" class="wp-block-heading">Changes made to&nbsp;<code>dmk_status.py</code></h3>



<p class="wp-block-paragraph"><strong>Colored status output.</strong> <code>STARTED</code> is now displayed in green, <code>STOPPED</code> in red — making it easier to spot unhealthy instances at a glance. To disable colors (for log files, CI pipelines, or terminals that don’t support ANSI), set <code>COLORED_STATUS=no</code> in your local configuration file (<code>dmkl</code>) by uncommenting the following line:</p>



<pre class="wp-block-code"><code># var::COLORED_STATUS::=::nowarn::no::  # Disable colored status output in dmk_status.py (yes/no)</code></pre>



<p class="wp-block-paragraph"><strong>CSV output.</strong> The table view now supports CSV export via the <code>--csv</code> option, useful for piping output to other tools or exporting to a file:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
# Export status as semicolon-delimited CSV
&amp;gt; dmk_status.py -t -a --csv &quot;;&quot;
Instance;Status;Version;Port;Bind IPs
mdb01;STARTED;8.0.26;27417;127.0.0.1
mdb02;STARTED;8.0.26;27418;127.0.0.1
mdbcfg01;STARTED;8.0.26;27017;127.0.0.1
mdbmgs01;STARTED;8.0.26;27030;127.0.0.1
</pre></div>


<p class="wp-block-paragraph">The session view (<code>sess</code>) supports the same option.</p>



<p class="wp-block-paragraph"><strong>Process-only check.</strong>&nbsp;The new&nbsp;<code>-p</code>&nbsp;/&nbsp;<code>--process</code>&nbsp;option performs a quick process presence check without connecting to MongoDB. This is faster and does not require credentials, making it useful for lightweight health checks:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
dmk_status.py -t -a --process
</pre></div>


<p class="wp-block-paragraph"><strong>Improved version display.</strong>&nbsp;The&nbsp;<code>-mv</code>&nbsp;option now shows all installed MongoDB versions side by side in a single table instead of separate blocks, making it much easier to compare binary versions across multiple installations.</p>



<p class="wp-block-paragraph"><strong>Session display refactoring.</strong>&nbsp;Session data gathering was moved into the instance class, and the display logic (including filtering and formatting) was centralized in&nbsp;<code>dmk_status.py</code>. This also fixes the&nbsp;<code>--include-inactive</code>&nbsp;flag, which was not working correctly in the previous release.</p>



<h3 id="h-new-nbsp-update-mongo-conf-py-nbsp-script" class="wp-block-heading">New&nbsp;<code>update_mongo_conf.py</code>&nbsp;script</h3>



<p class="wp-block-paragraph">The new&nbsp;<code>update_mongo_conf.py</code>&nbsp;script modifies MongoDB configuration file parameters from the command line using dot-notation for nested keys, without manually editing YAML:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
# Enable TLS on an existing instance
update_mongo_conf.py mdb01 net.tls.mode requireTLS
update_mongo_conf.py mdb01 net.tls.certificateKeyFile /u01/app/mongodb/admin/mdb01/secret/server.pem
</pre></div>


<h3 id="h-new-nbsp-set-uri-py-nbsp-script" class="wp-block-heading">New&nbsp;<code>set_uri.py</code>&nbsp;script</h3>



<p class="wp-block-paragraph">The new&nbsp;<code>set_uri.py</code>&nbsp;script generates and persists a&nbsp;<code>MONGO_URI</code>&nbsp;in the local DMK configuration for a given instance. It supports both standalone and replica set connection strings:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
# Standalone
set_uri.py mdb01 sa 127.0.0.1:27017

# Replica set
set_uri.py mdbrs01 rs 127.0.0.1:27411,127.0.0.1:27412,127.0.0.1:27413 rs1
</pre></div>


<p class="wp-block-paragraph">The resulting URI is stored in the local configuration file and available as&nbsp;<code>$MONGO_URI</code>&nbsp;in the instance context.</p>



<h3 id="h-improvements-to-nbsp-dmk-dbcreate-py" class="wp-block-heading">Improvements to&nbsp;<code>dmk_dbcreate.py</code></h3>



<p class="wp-block-paragraph"><code>dmk_dbcreate.py</code>&nbsp;now reads the&nbsp;<code>[instance_name]</code>&nbsp;section from the local DMK configuration file when creating an instance, so instance-specific variables defined in your local config are picked up automatically. Empty values for&nbsp;<code>MONGO_BACKUP</code>,&nbsp;<code>MONGO_JOURNAL</code>, and&nbsp;<code>MONGO_LOG</code>&nbsp;are also now accepted — directories are only created for paths that are explicitly set.</p>



<p class="wp-block-paragraph">The&nbsp;<code>storageEngine</code>&nbsp;key was removed from all YAML configuration templates. WiredTiger is the only storage engine available in MongoDB Community Edition, making the field redundant.</p>



<p class="wp-block-paragraph">A new&nbsp;<code>mongod.service.template_fork</code>&nbsp;systemd unit (<code>Type=simple</code>, delegating start/stop to&nbsp;<code>dmk_db_ctl.py</code>) was also added, alongside the existing&nbsp;<code>mongod.service.template</code>&nbsp;that runs&nbsp;<code>mongod</code>&nbsp;in the foreground.&nbsp;<code>dmk_dbcreate.py</code>&nbsp;generates the&nbsp;<code>mongod</code>&nbsp;unit for&nbsp;<code>mongod</code>&nbsp;instances and the&nbsp;<code>mongos</code>&nbsp;unit for routers.</p>



<h3 id="h-installation-improvements" class="wp-block-heading">Installation improvements</h3>



<p class="wp-block-paragraph"><strong>Auto-creation of&nbsp;<code>.bash_profile</code>.</strong>&nbsp;If the&nbsp;<code>.bash_profile</code>&nbsp;of the&nbsp;<code>mongodb</code>&nbsp;user does not contain the DMK block, DMK now creates it automatically from the template on first sourcing. If the file already exists with a DMK block, only that block is updated in place (with a backup created first). This removes a manual step from first-time installation.</p>



<p class="wp-block-paragraph"><strong>DMK temp files.</strong>&nbsp;The&nbsp;<code>dmk_env.sh</code>&nbsp;file used to source instance environments is now written to&nbsp;<code>$DMK_HOME/tmp/</code>&nbsp;rather than&nbsp;<code>/tmp</code>, keeping temporary DMK files within the DMK directory tree.</p>



<h3 id="h-security-improvements" class="wp-block-heading">Security improvements</h3>



<p class="wp-block-paragraph">The default&nbsp;<code>bindIp</code>&nbsp;in all DMK configuration templates was changed from&nbsp;<code>0.0.0.0</code>&nbsp;to&nbsp;<code>127.0.0.1</code>. This is a safer default for freshly created instances that limits network exposure from the start.</p>



<p class="wp-block-paragraph">A new&nbsp;<code>MONGO_TLS_CERTIFICATE_KEY_FILE</code>&nbsp;environment variable allows specifying a custom client certificate for DMK connections. This is useful for instances secured with&nbsp;<code>serverAuth</code>-only TLS, where the default certificate path may not be the right client certificate to use.</p>



<p class="wp-block-paragraph">New TLS templates for replica sets (<code>mongo_conf_rs_tls.yaml</code>,&nbsp;<code>mongo_conf_rs_tls_fork.yaml</code>,&nbsp;<code>mongo_conf_rs_keyfile.yaml</code>) were also added.</p>



<h3 id="h-aliases-and-environment-variables-added-in-dmk-2-5-0" class="wp-block-heading">Aliases and environment variables added in DMK 2.5.0</h3>



<p class="wp-block-paragraph">New aliases in DMK 2.5.0:</p>



<ul class="wp-block-list">
<li><code>mglogrotate</code>: rotate the MongoDB log file (<code>db.adminCommand({ logRotate: 1 })</code>).</li>



<li><code>certrotate</code>: rotate the TLS certificate of an instance (<code>db.rotateCertificates()</code>).</li>
</ul>



<p class="wp-block-paragraph">New environment variables:</p>



<ul class="wp-block-list">
<li><code>COLORED_STATUS</code>: set to <code>no</code> to disable colored status output in <code>dmk_status.py</code>. Enabled by default.</li>



<li><code>MONGO_TLS_CERTIFICATE_KEY_FILE</code>: custom client TLS certificate path for DMK connections.</li>



<li><code>MONGO_URI</code>: the MongoDB connection URI, now easily managed with <code>set_uri.py</code>.</li>



<li><code>INSTANCE_NAMING_CONVENTION</code>: the regular expression used to validate instance names. This variable is now <strong>optional</strong> — if not set, no naming convention is enforced.</li>
</ul>



<h3 id="h-bug-fixes" class="wp-block-heading">Bug fixes</h3>



<p class="wp-block-paragraph">A few notable bugs were fixed in this release:</p>



<ul class="wp-block-list">
<li><strong>Quoted values</strong> in the MongoDB configuration file (viewed with <code>vic</code> / <code>dmkc</code>) could cause the DMK environment to fail loading due to unescaped double quotes. This is now handled correctly.</li>



<li><strong>Restart</strong> could silently succeed without actually restarting the instance if it was still running. The stop phase now always waits for the instance to be fully stopped first.</li>



<li><strong><code>--include-inactive</code></strong> flag in the session view was not working correctly and has been fixed.</li>
</ul>



<h2 id="h-upgrading-from-an-earlier-version-of-dmk" class="wp-block-heading">Upgrading from an earlier version of DMK</h2>



<p class="wp-block-paragraph">If you are upgrading from DMK 2.4.0, replace the DMK folder with the new one:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
cd /u01/app/mongodb/local
mv dmk .dmk_old
unzip /path/to/dmk_mongodb-2.5.0.zip
dmk
</pre></div>


<p class="wp-block-paragraph">If you are upgrading from DMK 2.3.x or earlier, read the&nbsp;<a href="https://www.dbi-services.com/blog/mongodb-dmk-2-4-0-new-features/" target="_blank" rel="noreferrer noopener">release notes of DMK 2.4.0</a>&nbsp;first.</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-dmk-2-5-0-sharding-support-and-new-features/">MongoDB DMK 2.5.0: Sharding support and new features</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/mongodb-dmk-2-5-0-sharding-support-and-new-features/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MongoDB DMK 2.4.0 : new features</title>
		<link>https://www.dbi-services.com/blog/mongodb-dmk-2-4-0-new-features/</link>
					<comments>https://www.dbi-services.com/blog/mongodb-dmk-2-4-0-new-features/#respond</comments>
		
		<dc:creator><![CDATA[Julien Delattre]]></dc:creator>
		<pubDate>Fri, 13 Feb 2026 18:47:40 +0000</pubDate>
				<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[2.4.0]]></category>
		<category><![CDATA[DMK]]></category>
		<category><![CDATA[dmk_status]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Mongo]]></category>
		<category><![CDATA[mongodb]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=42906</guid>

					<description><![CDATA[<p>In this blog, I will present the new features introduced with the latest release (2.4.0) of the MongoDB DMK. The DMK is a set of standardized tools that aims at easing the work of DBAs by having dbi’s best practices embedded in common scripts across all the database servers of an organization. dbi services provides [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-dmk-2-4-0-new-features/">MongoDB DMK 2.4.0 : new features</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this blog, I will present the new features introduced with the latest release (<strong>2.4.0</strong>) of the MongoDB DMK.</p>



<p class="wp-block-paragraph">The DMK is a set of standardized tools that aims at easing the work of DBAs by having dbi’s best practices embedded in common scripts across all the database servers of an organization.</p>



<p class="wp-block-paragraph">dbi services provides the&nbsp;<a href="https://www.dbi-services.com/fr/produits/dmk-management-kit/" target="_blank" rel="noreferrer noopener">DMK</a>&nbsp;(<em>Database Management Kit</em>) to its customers for multiple technologies: Oracle, Postgres, MongoDB, etc. This toolkit is provided&nbsp;<strong>free of charge</strong>&nbsp;to all clients who work with dbi services on a consulting project.</p>



<h2 class="wp-block-heading" id="h-new-features-of-the-mongodb-dmk-in-2-4-0">New features of the MongoDB DMK in 2.4.0</h2>



<h3 class="wp-block-heading" id="changes-made-to-dmk_status.py-script">Changes made to <code>dmk_status.py</code> script</h3>



<ul class="wp-block-list">
<li>The table view (accessible with <code>dmk_status.py -t</code>, or the <code>tsta</code> alias) now supports sorting by any column. Use the <code>-o</code> option followed by the column name to specify the sorting column. For instance, use <code>-o='port'</code> to sort by port number. Sorting is <strong>ascending by default</strong>, but you can add a negative sign <code>-</code> before the column name for descending order, for instance <code>-o='-port'</code>. In addition to this, you can specify <strong>multiple columns</strong> for sorting, like <code>-o='-version,state'</code> to sort first by version and then by state.</li>
</ul>



<pre class="wp-block-code"><code>mongodb@dmkmongo:/home/mongodb/ &#091;mdb01] sta -o="-version"

Instance             | State                | Version | Port  | Bind IPs
-------------------------------------------------------------------------------
mdb01                | STARTED              | 8.0.16  | 27017 | 0.0.0.0
mdb02                | STARTED              | 8.0.16  | 27016 | 0.0.0.0
mdbrs01              | STARTED              | 8.0.15  | 27101 | 0.0.0.0</code></pre>



<ul class="wp-block-list">
<li>The session view (<code>dmk_status.py -s</code>, or <code>sess</code> alias) now <strong>supports filtering</strong>. You can filter with multiple criteria and combine them as needed. Here are the available filters:
<ul class="wp-block-list">
<li>Minimum runtime (<code>--min-runtime &lt;seconds&gt;</code>)</li>



<li>Client IP (<code>--client &lt;ip_address&gt;</code>)</li>



<li>User filtering (<code>--user &lt;username&gt;</code>)</li>



<li>Application name (<code>--app &lt;application_name&gt;</code>)</li>



<li>Database and collection (<code>--ns &lt;namespace&gt;</code>)</li>
</ul>
</li>
</ul>



<ul class="wp-block-list">
<li>You can also add the <code>--show-query</code> option to display the query for each session, which can be very useful in combination with the filters to quickly identify problematic queries. For instance, <code>--min-runtime 10 --show-query</code> will show all sessions that have been running for more than 10 seconds along with their queries.</li>
</ul>



<p class="wp-block-paragraph">Here is an example of session display filtering with the <code>--app</code> option:</p>



<pre class="wp-block-code"><code>mongodb@dmkmongo:/home/mongodb/ &#091;mdb01] sess --app DataGrip
2026-02-13 13:18:30 | INFO | Total sessions: 6, Active sessions: 6

--------------------------------------------------  Active MongoDB Sessions  --------------------------------------------------

Filters applied: app: DataGrip, active only

ID              USER                 CLIENT                 OP         NS                   COMMAND        TIME       APP
conn7           -                    192.168.105.1:60423    command    admin.$cmd           hello          7.82s      DataGrip
conn8           -                    192.168.105.1:60424    command    admin.$cmd           hello          7.83s      DataGrip
conn9           -                    192.168.105.1:60425    command    admin.$cmd           hello          7.83s      DataGrip

-------------------------------------------------------------------------------------------------------------------------------</code></pre>



<p class="wp-block-paragraph">When viewing the status of a single instance with <code>lsta</code> (or <code>dmk_status.py -l</code>), the list of databases is now displayed.</p>



<pre class="wp-block-code"><code>mongodb@dmkmongo:/home/mongodb/ &#091;mdb01] lsta
--------------------------   dbi services   ------------------------------

INSTANCE                 : mdb01
STATUS                   : STARTED
DATABASES                : dbapp01, dbapp02
VERSION                  : 8.0.16
BIND                     : 0.0.0.0
PORT                     : 27017
REPLICA SET STATUS       : No replication
CONFIGURATION FILE       : /u01/app/mongodb/admin/mdb01/etc/mdb01.conf
BIN PATH                 : /u01/app/mongodb/product/8.0.16/bin
DATA PATH                : /u02/mongodb/data/mdb01
LOG FILE                 : /u04/mongodb/log/mdb01/mdb01.log
BACKUP PATH              : /u90/mongodb/backup/mdb01

--------------------------------------------------------------------------</code></pre>



<h3 class="wp-block-heading" id="new-replicat-set-features"><a href="https://dbi-services.gitbook.io/dmk-mongodb/dmk-release-2.4.0/getting-started/release_notes_2.4.0#new-replicat-set-features"></a>New replicat set features</h3>



<ul class="wp-block-list">
<li>The <code>rsta</code> alias (equivalent of <code>dmk_status.py -r</code>) was improved to display more information.</li>
</ul>



<pre class="wp-block-code"><code>mongodb@dmkmongo:/home/mongodb/ &#091;mdbrs02] rsta

--------------------------------------------------  Replica Set Status Summary  --------------------------------------------------

INSTANCE                 : mdbrs02
REPLICA SET NAME         : rs01
DATE                     : 2026-02-13T12:21:43.755Z
MEMBER STATE             : SECONDARY
MEMBERS                  :
    NAME                  | STATE     | UPTIME | LAG  | OPTIME              | HEALTH | PRIORITY | SYNC FROM
    192.168.105.200:27017 | SECONDARY | 1m5s   | 0.0s | 2026-02-13T12:21:38 | UP     | 1        | 192.168.105.201:27017
    192.168.105.201:27017 | SECONDARY | 1m5s   | 0.0s | 2026-02-13T12:21:38 | UP     | 1        | 192.168.105.202:27017
    192.168.105.202:27017 | PRIMARY   | 48s    | 0.0s | 2026-02-13T12:21:38 | UP     | 1        |

----------------------------------------------------------------------------------------------------------------------------------</code></pre>



<ul class="wp-block-list">
<li>A <code>stepdown</code> alias was added to allow stepping down the primary directly from the DMK command line. Its definition is rather simple: <code>alias stepdown='msp --eval "rs.stepDown()"'</code>.</li>
</ul>



<h2 class="wp-block-heading" id="improvements-to-the-set_local_dmk_config.py-script"><a href="https://dbi-services.gitbook.io/dmk-mongodb/dmk-release-2.4.0/getting-started/release_notes_2.4.0#improvements-to-the-set_local_dmk_config.py-script"></a>Improvements to the <code>set_local_dmk_config.py</code> script</h2>



<p class="wp-block-paragraph">The <code>set_local_dmk_config.py</code> script now supports setting the local DMK configuration for custom instances by adding categories. Its usage doesn&#8217;t change, and you can find more about it in the <a href="https://dbi-services.gitbook.io/dmk-mongodb/dmk-release-2.4.0/references/environment_variables" target="_blank" rel="noreferrer noopener">Environment variables</a> page of the DMK documentation.</p>



<h2 class="wp-block-heading" id="better-support-for-instances-managed-with-systemd"><a href="https://dbi-services.gitbook.io/dmk-mongodb/dmk-release-2.4.0/getting-started/release_notes_2.4.0#better-support-for-instances-managed-with-systemd"></a>Better support for instances managed with <code>systemd</code></h2>



<p class="wp-block-paragraph">DMK better supports MongoDB instances that are managed with <code>systemd</code>. The <code>dmk_db_ctl.py</code> script will automatically detect if an instance is managed with <code>systemd</code> and use <code>systemctl</code> commands to start, stop, or restart the instance. This allows for <strong>better integration</strong> with the operating system and provides a more reliable management of MongoDB instances.</p>



<ul class="wp-block-list">
<li>Two new aliases were added to access <code>systemd</code> unit files of instances: <code>cdsys</code> to access the folder containing the unit file and <code>visys</code> to view the content of the unit file.</li>



<li>A <code>MONGO_SERVICE_NAME</code> variable was added to the configuration, which allows specifying the name of the <code>systemd</code> service for each instance. This is useful when the service name doesn&#8217;t follow a standard pattern based on the instance name. By default, <code>MONGO_SERVICE_NAME</code> is set to <code>mongod_${MONGO_INSTANCE}.service</code>, but you can overwrite it in your local configuration file if needed.</li>
</ul>



<h2 class="wp-block-heading" id="new-aliases-and-environment-variables"><a href="https://dbi-services.gitbook.io/dmk-mongodb/dmk-release-2.4.0/getting-started/release_notes_2.4.0#new-aliases-and-environment-variables"></a>New aliases and environment variables</h2>



<p class="wp-block-paragraph">Aliases added in DMK 2.4.0:</p>



<ul class="wp-block-list">
<li><code>cdp</code>: alias to access the <code>$MONGO_BASE/product</code> folder.</li>



<li><code>cdbin</code>: alias to access the MongoDB binaries folder of an instance.</li>



<li><code>dmkjs</code>: alias to access the DMK JavaScript folder. It is also available as a variable (<code>dmkjs=$DMK_HOME/js</code>).</li>



<li><code>cdsys</code>: alias to access the <code>systemd</code> unit files folder.</li>



<li><code>visys</code>: alias to view the <code>systemd</code> unit file of an instance.</li>



<li><code>stepdown</code>: alias to step down a primary instance with the <code>rs.stepDown()</code> command.</li>



<li><code>mgstatus</code>: alias to show the status of the current instance. It has the same output as the <code>lsta</code> alias, but it was added to work with the other <code>mgstop</code>, <code>mgstart</code> and <code>mgrestart</code> aliases.</li>
</ul>



<p class="wp-block-paragraph">Environment variables added in DMK 2.4.0:</p>



<ul class="wp-block-list">
<li><code>MONGO_SERVICE_NAME</code> environment variable to specify the name of the <code>systemd</code> service for each instance. By default, it is set to <code>mongod_${MONGO_INSTANCE}.service</code>, but you can overwrite it in your local configuration file if needed.</li>



<li><code>MONGO_CRED</code> variable to specify the path to the credential file of an instance. It is set by default to <code>${MONGO_BASE}/admin/${MONGO_INSTANCE}/secret/cred.yaml</code>, but you can overwrite it in your local configuration file if needed. This variable is used in the <code>msp</code> alias to automatically provide credentials when connecting to an instance with <code>mongosh</code>. More specifically, you can now set <code>MONGO_CRED</code> in the <code>[INSTANCE]</code> group in your local configuration file to have the <code>msp</code> alias automatically use the same credentials for all instances, which is very useful when managing multiple instances with the same credentials.</li>
</ul>



<h2 class="wp-block-heading" id="h-upgrading-from-an-earlier-version-of-dmk">Upgrading from an earlier version of DMK</h2>



<ul class="wp-block-list">
<li>If you are upgrading from 2.2.0 or earlier, please follow the instructions detailed in the <a href="https://www.dbi-services.com/blog/mongodb-dmk-2-3-new-features/" target="_blank" rel="noreferrer noopener">release notes of DMK 2.3</a>.</li>



<li>If you are upgrading from DMK 2.3, you just have to replace the current dmk folder with the new one.</li>
</ul>



<pre class="wp-block-code"><code># Go to the DMK folder
cd /u01/app/mongodb/local

# Rename the current dmk folder with a hidden folder
mv dmk .dmk_old

# Unzip the new version of the DMK
unzip /path/to/dmk_mongodb_2.4.0.zip

# Reload DMK
dmk
<a href="https://dbi-services.gitbook.io/dmk-mongodb/dmk-release-2.4.0/getting-started/versions_support"></a></code></pre>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-dmk-2-4-0-new-features/">MongoDB DMK 2.4.0 : new features</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/mongodb-dmk-2-4-0-new-features/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MongoDB DMK 2.3: new features</title>
		<link>https://www.dbi-services.com/blog/mongodb-dmk-2-3-new-features/</link>
					<comments>https://www.dbi-services.com/blog/mongodb-dmk-2-3-new-features/#respond</comments>
		
		<dc:creator><![CDATA[Julien Delattre]]></dc:creator>
		<pubDate>Mon, 15 Dec 2025 08:00:00 +0000</pubDate>
				<category><![CDATA[Database Administration & Monitoring]]></category>
		<category><![CDATA[Database management]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[DMK]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Mongo]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[tool]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=40312</guid>

					<description><![CDATA[<p>The latest MongoDB DMK release (2.3.1) introduces a lot of new features and important changes, which I will describe here. dbi services provides the DMK (Database Management Kit) to its customers for multiple technologies: Oracle, Postgres, MongoDB, etc. This toolkit is provided free of charge to all clients who work with dbi services on a [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-dmk-2-3-new-features/">MongoDB DMK 2.3: new features</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">The latest MongoDB DMK release (<strong>2.3.1</strong>) introduces a lot of <strong>new features and important changes</strong>, which I will describe here.</p>



<p class="wp-block-paragraph">dbi services provides the <a href="https://www.dbi-services.com/fr/produits/dmk-management-kit/" target="_blank" rel="noreferrer noopener">DMK</a> (Database Management Kit) to its customers for multiple technologies: Oracle, Postgres, MongoDB, etc. This toolkit is provided <strong>free of charge</strong> to all clients who work with dbi services on a consulting project.</p>



<p class="wp-block-paragraph">The DMK is a set of standardized tools aiming at easing the work of DBAs, by having dbi&#8217;s best practices embedded in common scripts across all the database servers of an organization.</p>



<h2 id="h-new-features-of-the-mongodb-dmk" class="wp-block-heading">New features of the MongoDB DMK</h2>



<h4 id="h-rewriting-of-the-project" class="wp-block-heading">Rewriting of the project</h4>



<p class="wp-block-paragraph">The most significant changes in the MongoDB DMK is the <strong>rewriting of all old Perl scripts into new Python scripts</strong>. On top of being <strong>more adapted to the MongoDB ecosystem</strong>, these will <strong>improve modularity</strong> for customers wanting to write their own packages.</p>



<p class="wp-block-paragraph">It means that all utility scripts are now named <code>.py</code> instead of <code>.sh</code>, and apart from new features that have been added, the basic behavior stays the same for all of them.</p>



<p class="wp-block-paragraph"></p>



<h4 id="h-dmk-configuration-file" class="wp-block-heading">DMK configuration file</h4>



<p class="wp-block-paragraph">Before release 2.3.0, only one configuration file existed in <code>$DMK_HOME/etc</code>. There is now a <strong>second configuration file</strong> in <code>~/.DMK/dmk.conf.local</code>, which will overwrite default configuration options. See the GitBook section on <a href="https://dbi-services.gitbook.io/dmk-mongodb/installation-and-setup/using_dmk" target="_blank" rel="noreferrer noopener">Using DMK</a> for more information.</p>



<p class="wp-block-paragraph"></p>



<h4 id="h-new-default-directories-and-more-versatility" class="wp-block-heading">New default directories and more versatility</h4>



<p class="wp-block-paragraph">The <a href="https://dbi-services.gitbook.io/dmk-mongodb/installation-and-setup/optimal_flexible_architecture" target="_blank" rel="noreferrer noopener">Optimal Flexible Architecture</a> (OFA) has <strong>new recommendations</strong>. Specifically, the new default architecture is the following:</p>



<ul class="wp-block-list">
<li><code>/u01</code> for binaries and admin folders</li>



<li><code>/u02</code> for database files</li>



<li><code>/u03</code> for journal files</li>



<li><code>/u04</code> for log files</li>



<li><code>/u90</code> for backup files</li>
</ul>



<p class="wp-block-paragraph">Even though dbi suggests OFA as a good standard for MongoDB installations, we know that a lot of legacy installations will not use this kind of architecture. This is why the <strong>DMK is now more versatile</strong>, and with the use of the local configuration file described above, it has never been easier to adapt the DMK to your needs.</p>



<h4 id="h-new-aliases-and-environment-variables" class="wp-block-heading">New aliases and environment variables</h4>



<p class="wp-block-paragraph">Some aliases were changed in this release, others were added. See <a href="https://dbi-services.gitbook.io/dmk-mongodb/references/environment_variables" target="_blank" rel="noreferrer noopener">Environment Variables</a> and <a href="https://dbi-services.gitbook.io/dmk-mongodb/references/aliases" target="_blank" rel="noreferrer noopener">Aliases</a> in the documentation for more information.</p>



<ul class="wp-block-list">
<li><code>mgstart</code>, <code>mgstop</code>, <code>mgrestart</code> are new aliases to manage a MongoDB instance.</li>



<li><code>vic</code> now opens the MongoDB instance configuration file.</li>



<li><code>vilst</code> now opens the <code>$DMK_HOME/etc/mongodb.lst</code> file.</li>



<li><code>sta</code>, <code>lsta</code>, <code>tsta</code>, <code>rsta</code> are new aliases for instance status display.</li>



<li><code>vil</code>, <code>cdl</code>, <code>tal</code> are new aliases to view, access and tail log files of MongoDB instances.</li>



<li><code>dmkc</code> opens DMK default configuration file.</li>



<li><code>dmkl</code> opens DMK local configuration file, which overrides the default configuration file.</li>
</ul>



<h4 id="other-changes" class="wp-block-heading">Other changes<a href="https://dbi-services.gitbook.io/dmk-mongodb/getting-started/release_notes_2.3.1#other-changes"></a></h4>



<ul class="wp-block-list">
<li>A script named <code>set_local_dmk_config.py</code> was created to automate local configuration file changes. See <a href="https://dbi-services.gitbook.io/dmk-mongodb/references/environment_variables" target="_blank" rel="noreferrer noopener">Environment Variables</a> for more details.</li>



<li><strong>Backups are no longer compressed by default</strong>, and the option to compress them has been added to the <code>dmk_dbbackup.py</code> script.</li>



<li>And of course, corrections of bugs.<a href="https://dbi-services.gitbook.io/dmk-mongodb/getting-started/release_notes_2.3.1#new-scripts"></a></li>
</ul>



<h2 id="h-installing-the-dmk-for-the-first-time" class="wp-block-heading">Installing the DMK for the first time</h2>



<p class="wp-block-paragraph">Installing the DMK is always fairly easy. If you follow the OFA, <strong>just unzip the package and source</strong> <code>dmk.sh</code>.</p>



<pre class="wp-block-code"><code>&#091;root@vm00 ~]$ su - mongodb
&#091;mongodb@vm00 ~]$ unzip -oq dmk_mongodb-2.3.1.zip -d /u01/app/mongodb/local
&#091;mongodb@vm00 ~]$ . /u01/app/mongodb/local/dmk/bin/dmk.sh
2025-12-04 10:03:48 | INFO | DMK_HOME environment variable is not defined.
2025-12-04 10:03:48 | INFO | First time installation of DMK.
2025-12-04 10:03:48 | INFO | DMK has been extracted to /u01/app/mongodb/local/dmk
2025-12-04 10:03:48 | INFO | Using DMK_HOME=/u01/app/mongodb/local/dmk
2025-12-04 10:03:48 | INFO | Default configuration file '/u01/app/mongodb/local/dmk/etc/dmk.conf.default' does not exist. Creating it.
2025-12-04 10:03:48 | INFO | Copying template file '/u01/app/mongodb/local/dmk/templates/etc/dmk.conf.unix' to '/u01/app/mongodb/local/dmk/etc/dmk.conf.default'
2025-12-04 10:03:48 | INFO | Local configuration file does not exist. Creating it.
2025-12-04 10:03:48 | INFO | Copying template file '/u01/app/mongodb/local/dmk/templates/etc/dmk.conf.local.template' to '/home/mongodb/.dmk/dmk.conf.local'
2025-12-04 10:03:48 | INFO | Creating symlink '/u01/app/mongodb/local/dmk/etc/dmk.conf.local' to '/home/mongodb/.dmk/dmk.conf.local'
2025-12-04 10:03:48 | WARNING | MONGO_BASE environment variable is not set. Trying to retrieve it from DMK_HOME (/u01/app/mongodb/local/dmk).
2025-12-04 10:03:48 | WARNING | MONGO_BASE set to '/u01/app/mongodb' based on DMK_HOME location.
2025-12-04 10:03:48 | WARNING | If you're running DMK for the first time, you can ignore these warnings.
2025-12-04 10:03:48 | WARNING | Otherwise, please set MONGO_BASE in /home/mongodb/.DMK before sourcing DMK.
2025-12-04 10:03:48 | WARNING | File '/u01/app/mongodb/etc/mongodb.lst' does not exist. Creating an empty file.
2025-12-04 10:03:48 | INFO | Creating DMK source file at '/home/mongodb/.DMK' with the following content:
2025-12-04 10:03:48 | INFO | DMK_HOME=/u01/app/mongodb/local/dmk
2025-12-04 10:03:48 | INFO | PYTHON_BIN=/usr/bin/python3
2025-12-04 10:03:48 | INFO | MONGO_BASE=/u01/app/mongodb
2025-12-04 10:03:48 | WARNING | Please make sure to source the .DMK file in your shell profile (e.g., .bash_profile).
2025-12-04 10:03:48 | WARNING | An example is provided at /u01/app/mongodb/local/dmk/templates/profile/dmk.mongodb.profile</code></pre>



<p class="wp-block-paragraph">If you don&#8217;t follow the OFA, you should <strong>define the following mandatory variables before running the DMK</strong>, inside the <code>/home/mongodb/.DMK</code> file:</p>



<ul class="wp-block-list">
<li><code>DMK_HOME</code>: path to the DMK main folder</li>



<li><code>PYTHON_BIN</code>: path to the Python binaries (3.6+ necessary, which is the default for Linux 8-like platforms)</li>



<li><code>MONGO_BASE</code></li>
</ul>



<pre class="wp-block-code"><code>&#091;root@vm00 ~]$ su - mongodb
&#091;mongodb@vm00 ~]$ echo "DMK_HOME=/u01/app/mongodb/local/dmk" &gt; ~/.DMK
&#091;mongodb@vm00 ~]$ echo "PYTHON_BIN=/usr/bin/python3" &gt;&gt; ~/.DMK
&#091;mongodb@vm00 ~]$ echo "MONGO_BASE=/u01/app/mongodb" &gt;&gt; ~/.DMK

&#091;mongodb@vm00 ~]$ cat ~/.DMK
export DMK_HOME=/u01/app/mongodb/local/dmk
export PYTHON_BIN=/usr/bin/python3
export MONGO_BASE=/u01/app/mongodb</code></pre>



<h4 id="h-loading-dmk-at-login" class="wp-block-heading">Loading DMK at login</h4>



<p class="wp-block-paragraph">If you want the DMK to be loaded when logging in, you should add the following code block to the <code>.bash_profile</code> of the <code>mongodb</code> user:</p>



<pre class="wp-block-code"><code># BEGIN DMK BLOCK
if &#091; -z "$DMK_HOME" ]; then
  if &#091; -f "$HOME/.DMK" ]; then
    . "$HOME/.DMK"
  else
    echo "$HOME/.DMK file does not exist"
    return 1
  fi
fi

# Launched at login
. ${DMK_HOME}/bin/dmk.sh &amp;&amp; ${PYTHON_BIN} ${DMK_HOME}/bin/dmk_status.py --table --all
# END DMK BLOCK</code></pre>



<p class="wp-block-paragraph">After this, you can just log in again. <strong>The installation is complete !</strong></p>



<h2 id="h-migrating-from-a-former-version-of-the-dmk" class="wp-block-heading">Migrating from a former version of the DMK</h2>



<p class="wp-block-paragraph">If you already have the MongoDB DMK installed on your systems, there are a few more steps to take for this specific upgrade, because we switched from old Perl libraries to Python.</p>



<p class="wp-block-paragraph">You first need to <strong>adapt the <code>.DMK</code> file</strong>, as described in the installation steps.</p>



<pre class="wp-block-code"><code>&#091;mongodb@vm00 ~]$ cat ~/.DMK
export DMK_HOME=/u01/app/mongodb/local/dmk
export PYTHON_BIN=/usr/bin/python3
export MONGO_BASE=/u01/app/mongodb</code></pre>



<p class="wp-block-paragraph">Then, <strong>move the former DMK folder and unzip the new version</strong> of the DMK. The old DMK should be a hidden directory, otherwise DMK will consider it as a custom package !</p>



<pre class="wp-block-code"><code>mongodb@vm00:/home/mongodb/ &#091;DUMMY] cd /u01/app/mongodb/local/
mongodb@vm00:/u01/app/mongodb/local/ &#091;DUMMY] ls -l
drwxrwx---. 10 mongodb mongodb 118 Jul  1 04:34 dmk
mongodb@vm00:/u01/app/mongodb/local/ &#091;DUMMY] mv dmk .dmk_old
mongodb@vm00:/u01/app/mongodb/local/ &#091;DUMMY] unzip /u01/app/mongodb/artifacts/dmk_mongodb-2.3.1.zip
mongodb@vm00:/u01/app/mongodb/local/ &#091;DUMMY] ls -ail
100690250 drwxrwx---.  8 mongodb mongodb  96 Jul  1 04:24 dmk
 33554663 drwxrwx---. 10 mongodb mongodb 118 Jul  1 04:34 .dmk_old</code></pre>



<p class="wp-block-paragraph"><strong>Update your <code>.bash_profile</code></strong> to remove all traces of the former DMK loading mechanism. Here is an example of the minimal DMK block in the template file:</p>



<pre class="wp-block-code"><code># BEGIN DMK BLOCK
if &#091; -z "$DMK_HOME" ]; then
    if &#091; -f "$HOME/.DMK" ]; then
        . "$HOME/.DMK"
    else
        echo "$HOME/.DMK file does not exist. It is needed to source DMK at login. Run '. &lt;DMK_HOME&gt;/bin/dmk.sh' or 'source &lt;DMK_HOME&gt;/bin/dmk.sh' to source DMK manually this time."
        return 1
    fi
fi

# Launched at login
. ${DMK_HOME}/bin/dmk.sh &amp;&amp; ${PYTHON_BIN} ${DMK_HOME}/bin/dmk_status.py --table --all
# END DMK BLOCK</code></pre>



<p class="wp-block-paragraph">Last but not least, you will have to <strong>customize your local DMK configuration file</strong> <code>~/.dmk/dmk.conf.local</code>. You can use the <code>set_local_dmk_config.py</code> script to help yourself with the modifications.</p>



<pre class="wp-block-code"><code>mongodb@vm00:/u01/app/mongodb/admin/ &#091;mdb01] set_local_dmk_config.py INSTANCE MONGO_JOURNAL "\${MONGO_DATA_ROOT}/\${MONGO_INSTANCE}/journal"
Backup created: /home/mongodb/.dmk/dmk.conf.bak_20251024_084959
Updated MONGO_JOURNAL in &#091;INSTANCE]
Old value: var::MONGO_JOURNAL::=::nowarn::"${MONGO_JOURNAL_ROOT}/${MONGO_INSTANCE}"::
New value: var::MONGO_JOURNAL::=::nowarn::"${MONGO_DATA_ROOT}/${MONGO_INSTANCE}/journal"::
Use 'dmkc' and 'dmkl' aliases to quickly view default and local configuration files.</code></pre>



<p class="wp-block-paragraph">For any questions regarding the MongoDB DMK, take a look at <a href="https://dbi-services.gitbook.io/dmk-mongodb" target="_blank" rel="noreferrer noopener">the documentation</a> or feel free to <a href="mailto:julien.delattre@dbi-services.com">contact me</a>.</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-dmk-2-3-new-features/">MongoDB DMK 2.3: new features</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/mongodb-dmk-2-3-new-features/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Setting up TLS encryption and authentication in MongoDB</title>
		<link>https://www.dbi-services.com/blog/setting-up-tls-encryption-and-authentication-in-mongodb/</link>
					<comments>https://www.dbi-services.com/blog/setting-up-tls-encryption-and-authentication-in-mongodb/#respond</comments>
		
		<dc:creator><![CDATA[Julien Delattre]]></dc:creator>
		<pubDate>Mon, 10 Nov 2025 08:00:00 +0000</pubDate>
				<category><![CDATA[Database Administration & Monitoring]]></category>
		<category><![CDATA[Database management]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[authenticationdatabase]]></category>
		<category><![CDATA[Authorization]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[mongoservererror]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[TLS]]></category>
		<category><![CDATA[tlscertificatekeyfile]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=38825</guid>

					<description><![CDATA[<p>When securing a MongoDB deployment, protecting sensitive data is paramount. MongoDB supports encryption throughout the lifecycle of the data, with three primary types of data encryption : Among these, encryption in transit is fundamental : it protects data as it moves between your application and the database. In MongoDB, this is achieved through TLS (Transport [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/setting-up-tls-encryption-and-authentication-in-mongodb/">Setting up TLS encryption and authentication in MongoDB</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">When <strong>securing a MongoDB deployment</strong>, protecting sensitive data is paramount. MongoDB supports encryption <strong>throughout the lifecycle</strong> of the data, with three primary types of data encryption :</p>



<ul class="wp-block-list">
<li>Encryption <strong>in transit</strong></li>



<li>Encryption <strong>at rest</strong></li>



<li>Encryption <strong>in use</strong></li>
</ul>



<p class="wp-block-paragraph"><br>Among these, <strong>encryption in transit</strong> is fundamental : it protects data as it moves between your application and the database. In MongoDB, this is achieved through <strong>TLS (Transport Layer Security)</strong>, which ensures that communication remains private and secure. You have two options when it comes to using TLS for your database :</p>



<ul class="wp-block-list">
<li>Using TLS for <strong>encryption</strong> only.</li>



<li>Using TLS both for <strong>encryption</strong> and <strong>authentication</strong> to the database.</li>
</ul>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading" id="h-setting-up-tls-for-encryption">Setting up TLS for encryption</h2>



<h3 class="wp-block-heading" id="h-create-a-certificate-authority">Create a Certificate Authority</h3>



<p class="wp-block-paragraph">We&#8217;ll first create a <strong>Certificate Authority</strong>. These certificates will be self-signed, which is fine for testing, but <strong>you shouldn&#8217;t use self-signed certificates in a production environment !</strong> On Linux, use the <code>openssl</code> library to generate the certificates.</p>



<pre class="wp-block-code"><code>openssl req -newkey rsa:4096 -nodes -x509 -days 365 -keyout ca.key -out ca.pem -subj "/C=CH/ST=ZH/L=Zurich/O=dbi/OU=MongoDBA/CN=vm.domain.com"</code></pre>



<p class="wp-block-paragraph">Here is a description of some important parameters of the commands :</p>



<ul class="wp-block-list">
<li><code>-newkey rsa:4096</code> : Generates a new private key and a certificate request using RSA with a 4096-bit key size.</li>



<li><code>-nodes</code> : Skips password encryption of the private key. Without it, OpenSSL would prompt you to set a passphrase.</li>



<li><code>-x509</code> : Generates a self-signed certificate. <code>x509</code> is supported by MongoDB.</li>



<li><code>-days 365</code> : Validity of the certificate in days.</li>



<li><code>-keyout ca.key</code> : Filename for the private key.</li>



<li><code>-out ca.pem</code> : Filename for the certificate.</li>



<li><code>-subj "..."</code> : Provides the subject&#8217;s Distinguished Name (DN). If you don&#8217;t specify it, OpenSSL will prompt for each field.</li>
</ul>



<h3 class="wp-block-heading" id="h-create-a-server-certificate">Create a Server Certificate</h3>



<p class="wp-block-paragraph">Then, we&#8217;ll create the server certificate for the MongoDB instance. In the <code>openssl-server.cnf</code> file below, you should change the <code>req_distinguished_name</code> fields with what you used while creating the Certificate Authority, and replace <code>vm.domain.com</code> by the name of your machine.</p>



<p class="wp-block-paragraph">If you only have an IP and no DNS entry for your VM, use <code>IP.1</code> instead of <code>DNS.1</code> in the <code>alt_names</code> section.</p>



<pre class="wp-block-code"><code>cat &gt; openssl-server.cnf &lt;&lt;EOF
&#091; req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no

&#091; req_distinguished_name ]
C = CH
ST = ZH
L = Zurich
O = dbi
OU = MongoDBA
<strong>CN = myVM
</strong>
&#091; v3_req ]
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

&#091; alt_names ]
<strong>DNS.1 = myVM
</strong>EOF</code></pre>



<p class="wp-block-paragraph">Then, generates the certificate with these commands :</p>



<pre class="wp-block-code"><code>openssl req -newkey rsa:4096 -nodes -keyout mongodb-server.key -out mongodb-server.csr -config openssl-server.cnf

openssl x509 -req -in mongodb-server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out mongodb-server.crt -days 365 -extensions v3_req -extfile openssl-server.cnf

cat mongodb-server.key mongodb-server.crt &gt; mongodb-server.pem</code></pre>



<h3 class="wp-block-heading" id="h-create-a-client-certificate">Create a Client Certificate</h3>



<p class="wp-block-paragraph">Finally, we&#8217;ll create a client certificate. The process is the same, with a few tweaks :</p>



<ul class="wp-block-list">
<li><code>OU</code> should be different from the one from the server certificate. It is not mandatory for the communication, but it will be for the authentication if you decide to enable it.</li>



<li><code>CN</code> should also be different.</li>



<li><code>extendedKeyUsage</code> should be set with <code>clientAuth</code> instead of <code>serverAuth</code>.</li>
</ul>



<pre class="wp-block-code"><code>cat &gt; openssl-client.cnf &lt;&lt;EOF
&#091; req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no

&#091; req_distinguished_name ]
C = CH
ST = ZH
L = Zurich
O = dbi
<strong>OU = MongoDBAClient
CN = userApp
</strong>
&#091; v3_req ]
keyUsage = digitalSignature, keyEncipherment
<strong>extendedKeyUsage = clientAuth
</strong>EOF</code></pre>



<p class="wp-block-paragraph">The creation of the certificate is the same.</p>



<pre class="wp-block-code"><code>openssl req -newkey rsa:4096 -nodes -keyout mongodb-client.key -out mongodb-client.csr -config openssl-client.cnf

openssl x509 -req -in mongodb-client.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out mongodb-client.crt -days 365 -extensions v3_req -extfile openssl-client.cnf

cat mongodb-client.key mongodb-client.crt &gt; mongodb-client.pem</code></pre>



<h3 class="wp-block-heading" id="h-mongodb-configuration-change">MongoDB Configuration Change</h3>



<p class="wp-block-paragraph">Make sure to set permissions correctly for your certificates.</p>



<pre class="wp-block-code"><code>chmod 600 ca.pem mongodb-server.pem mongodb-client.pem
chown mongod: ca.pem mongodb-server.pem mongodb-client.pem</code></pre>



<p class="wp-block-paragraph">Now, you can change your MongoDB configuration file to include the certificates. Simply add the <code>net.tls</code> part to your <code>mongod.conf</code> file.</p>



<pre class="wp-block-code"><code>net:
  bindIp: yourIP
  port: 27017
  <strong>tls:
    mode: requireTLS
    certificateKeyFile: /path/to/mongodb-server.pem
    CAFile: /path/to/ca.pem</strong></code></pre>



<p class="wp-block-paragraph">You can now restart your MongoDB instance with <code>systemctl restart mongod</code> (or whatever you&#8217;re using), and then try the connection to your instance for your client. Of course, the port mentioned in the <code>net.port</code> field of your configuration file shouldn&#8217;t be blocked by your firewall.</p>



<pre class="wp-block-code"><code>&gt; mongosh --host myVM --port 27017 --tls --tlsCertificateKeyFile mongodb-client.pem --tlsCAFile ca.pem
Current Mongosh Log ID:	682c9641bbe4593252ee7c8c
Connecting to:		mongodb://vmIP:27017/?directConnection=true&amp;tls=true&amp;tlsCertificateKeyFile=Fclient.pem&amp;tlsCAFile=ca.pem&amp;appName=mongosh+2.5.1
Using MongoDB:		8.0.9
Using Mongosh:		2.5.1

For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

test&gt;</code></pre>



<p class="wp-block-paragraph">You&#8217;re now connected to your MongoDB instance through TLS ! And if you&#8217;re not using the certificate, the <code>requireTLS</code> mode prevents the connection from being established, and generated these error messages in your logs :</p>



<pre class="wp-block-code"><code>{"t":{"$date":"2025-05-21T04:43:55.277+00:00"},"s":"I",  "c":"EXECUTOR", "id":22988,   "ctx":"conn52","msg":"Error receiving request from client. Ending connection from remote","attr":{"error":{"code":141,"codeName":"SSLHandshakeFailed","errmsg":"<strong>The server is configured to only allow SSL connections</strong>"},"remote":"IP:50100","connectionId":52}}</code></pre>



<p class="wp-block-paragraph"><em>If you want to learn more about MongoDB logs, I wrote a blog on this topic: <a href="https://www.dbi-services.com/blog/mongodb-log-analysis-a-comprehensive-guide/">MongoDB Log Analysis : A Comprehensive Guide</a>.</em></p>



<h2 class="wp-block-heading" id="h-setting-up-tls-authentication">Setting up TLS authentication</h2>



<p class="wp-block-paragraph">Now that you&#8217;re connected, we will set up authentication so that you can be connected as a specific user to MongoDB. Using the already established connection, create a user in the <code>$external</code> database. Each client certificate that you create can be mapped to one MongoDB user. Retrieve the username that you will use :</p>



<pre class="wp-block-code"><code>&gt; openssl x509 -in mongodb-client.pem -inform PEM -subject -nameopt RFC2253 | grep subject
subject=<strong>CN=userApp,OU=MongoDBA,O=dbi,L=Zurich,ST=ZH,C=CH</strong></code></pre>



<p class="wp-block-paragraph">And then create the user in the <code>$external</code> database, using the existing MongoDB connection :</p>



<pre class="wp-block-code"><code>test&gt; db.getSiblingDB("$external").runCommand({
  createUser: "<strong>CN=userApp,OU=MongoDBA,O=dbi,L=Zurich,ST=ZH,C=CH</strong>",
  roles: &#091;
    { role: "userAdminAnyDatabase", db: "admin" }
  ]
});</code></pre>



<p class="wp-block-paragraph">To check that everything works as intended, you can try to display collections in the <code>admin</code> database. For the moment, there is no error because you have all the rights to do it (no authorization is enforced).</p>



<pre class="wp-block-code"><code>test&gt; use admin
switched to db admin
admin&gt; show collections;
system.users
system.version</code></pre>



<p class="wp-block-paragraph">You can now edit the MongoDB configuration file by adding the <code>net.tls.allowConnectionsWithoutCertificates</code> set to <code>true</code>, and the <code>security.authorization</code> flag set to <code>enabled</code>. The <code>mongod.conf</code> file should look like this :</p>



<pre class="wp-block-code"><code>net:
  bindIp: X.X.X.X
  port: XXXXX
  tls:
    mode: requireTLS
    certificateKeyFile: /path/to/mongodb-server.pem
    CAFile: /path/to/ca.pem
<strong>    allowConnectionsWithoutCertificates: false
</strong>
<strong>security:
  authorization: enabled</strong></code></pre>



<p class="wp-block-paragraph">After restarting with <code>systemctl restart mongod</code>, you can now connect again. If you use the same command as before, you will log in without authentication, and get the error below whenever you try to do anything :</p>



<pre class="wp-block-code"><code>MongoServerError&#091;Unauthorized]: Command listCollections requires authentication</code></pre>



<p class="wp-block-paragraph">So you should now connect via this command :</p>



<pre class="wp-block-code"><code>mongosh --host vmIP --port 27017 --tls --tlsCertificateKeyFile mongodb-client.pem --tlsCAFile ca.pem --authenticationDatabase '$external' --authenticationMechanism MONGODB-X509</code></pre>



<p class="wp-block-paragraph">If you want to show the <code>admin</code> collections, you will now get an error, because your user only has the <code>userAdminAnyDatabase</code> role granted (this role was chosen during the user creation, see above).</p>



<pre class="wp-block-code"><code>admin&gt; show collections
MongoServerError&#091;Unauthorized]: not authorized on admin to execute command { listCollections: 1, filter: {}, cursor: {}, nameOnly: true, authorizedCollections: false, lsid: { id: UUID("9c48b4c4-7702-49ce-a97c-52763b2ad6b3") }, $db: "admin" }</code></pre>



<p class="wp-block-paragraph">But it&#8217;s fine, you can grant yourself more roles (<code>readWriteAnyDatabase</code>, for instance) and create new users if you want.</p>



<p class="wp-block-paragraph">The <strong>communication between the client and the server is now fully secured</strong>. Congratulations !</p>



<h4 class="wp-block-heading" id="h-mongoservererror-badvalue">MongoServerError[BadValue]</h4>



<p class="wp-block-paragraph"><em>Side note</em> : if you ever encounter this error:</p>



<pre class="wp-block-code"><code>MongoServerError&#091;BadValue]: Cannot create an x.509 user with a subjectname that would be recognized as an internal cluster member</code></pre>



<p class="wp-block-paragraph">&#8230; make sure to follow the <a href="https://www.ietf.org/rfc/rfc2253.txt RFC-2253">RFC-2253</a> standards. For instance, you could have this error if one of the field is too long. Also, as a reminder, the client certificate should have a different Distinguished Name (DN) than the server certificate (see <a href="https://www.mongodb.com/docs/manual/core/security-x.509/">documentation</a> for more information).</p>



<p class="wp-block-paragraph"></p>
<p>L’article <a href="https://www.dbi-services.com/blog/setting-up-tls-encryption-and-authentication-in-mongodb/">Setting up TLS encryption and authentication in MongoDB</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/setting-up-tls-encryption-and-authentication-in-mongodb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using Oracle API for MongoDB on OCI</title>
		<link>https://www.dbi-services.com/blog/using-oracle-api-for-mongodb-on-oci/</link>
					<comments>https://www.dbi-services.com/blog/using-oracle-api-for-mongodb-on-oci/#respond</comments>
		
		<dc:creator><![CDATA[Julien Delattre]]></dc:creator>
		<pubDate>Wed, 15 Oct 2025 06:00:00 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[OCI]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Autonomous Database]]></category>
		<category><![CDATA[Document]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[mongoservererror]]></category>
		<category><![CDATA[query]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=38488</guid>

					<description><![CDATA[<p>If you&#8217;ve ever had to deal with MongoDB after years (or even decades) of working with SQL, you&#8217;ve probably realized that querying JSON documents can sometimes be painful, to say the least. In response to this, Oracle (and others) use a not-so-native adaptation of SQL to query JSON documents. And if you&#8217;ve ever had to [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/using-oracle-api-for-mongodb-on-oci/">Using Oracle API for MongoDB on OCI</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">If you&#8217;ve ever had to deal with <strong>MongoDB</strong> after years (or even decades) of working with <strong>SQL</strong>, you&#8217;ve probably realized that querying JSON documents can sometimes be painful, to say the least.</p>



<p class="wp-block-paragraph">In response to this, <strong>Oracle</strong> (and others) use a not-so-native adaptation of SQL to query JSON documents. And if you&#8217;ve ever had to deal with these SQL-based JSON queries, you may have found yourself thinking (in hindsight) that querying JSON documents with <strong>MQL (MongoDB Query Language)</strong> wasn&#8217;t <em>that</em> painful after all. And rightly so : JSON documents are very different from relational tables, and there is <strong>no easy way to continue using SQL without learning </strong>some new syntax.</p>



<p class="wp-block-paragraph">Oracle likely came to the same conclusion, and offers an <strong>API dedicated to MongoDB</strong> natives. The idea is simple : to ease the work of developers and database administrators when deciding to migrate from MongoDB to Oracle (and the other way around ?&#8230;)</p>



<p class="wp-block-paragraph">On <strong>Oracle Cloud Infrastructure (OCI)</strong>, this means being able to connect to <strong>Autonomous Databases (ADB)</strong>. As a reminder, you have two of them included in the <strong>Always Free Tier</strong> of OCI, so you can play around with this feature for free before deciding to migrate to the cloud.</p>



<p class="wp-block-paragraph"></p>



<h2 id="h-setting-up-the-oracle-mongodb-api-on-oci" class="wp-block-heading">Setting up the Oracle MongoDB API on OCI</h2>



<p class="wp-block-paragraph">When creating an Autonomous Database, you can decide on multiple workloads types, including a <strong>JSON workload</strong>. However, the MongoDB API does not strictly require the JSON workload type to work.</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="903" height="173" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/image-7.png" alt="" class="wp-image-38493" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/image-7.png 903w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/image-7-300x57.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/image-7-768x147.png 768w" sizes="(max-width: 903px) 100vw, 903px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">However, the <strong>network access setting</strong> of your Autonomous Database <strong>must be non-default</strong> with one of the following options enabled :</p>



<ul class="wp-block-list">
<li><em>Secure access from allowed IPs and VCNs only</em></li>



<li><em>Private endpoint access only</em></li>
</ul>



<p class="wp-block-paragraph">For instance, when using the <strong><em>Secure access from allowed IPs and VCNs only</em></strong> option, you can add any IP address to the <strong>Access Control List (ACL)</strong>, including your own.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="876" height="496" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_network_access_full.png" alt="" class="wp-image-38517" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_network_access_full.png 876w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_network_access_full-300x170.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_network_access_full-768x435.png 768w" sizes="(max-width: 876px) 100vw, 876px" /><figcaption class="wp-element-caption"><em><strong>Warning</strong> : If your IP address changes, you will have to update the ACL !</em></figcaption></figure>



<p class="wp-block-paragraph">After creating the ADB (Autonomous Database), you can check in the <em><strong>Tool configuration</strong></em> tab the MongoDB API is enabled (it should be, by default).</p>



<figure class="wp-block-image size-full"><img decoding="async" width="830" height="182" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_tool_configuration_tab.png" alt="" class="wp-image-38514" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_tool_configuration_tab.png 830w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_tool_configuration_tab-300x66.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_tool_configuration_tab-768x168.png 768w" sizes="(max-width: 830px) 100vw, 830px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="557" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_mongo_db_api_enabled-1-1024x557.png" alt="" class="wp-image-38516" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_mongo_db_api_enabled-1-1024x557.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_mongo_db_api_enabled-1-300x163.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_mongo_db_api_enabled-1-768x418.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_mongo_db_api_enabled-1.png 1152w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Then you can go in <em><strong>Database actions</strong></em> &gt; <em><strong>Database Users</strong></em> to either create a user or modify an existing one, with the following privileges : <code>CREATE SESSION</code>, <code>CREATE RESOURCE</code> (default), and the <code>SODA_APP</code> role. After creation, you should <strong>enable REST</strong> as shown below. This will allow the API to work on that particular schema.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="146" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_enable_REST-1024x146.png" alt="" class="wp-image-38513" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_enable_REST-1024x146.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_enable_REST-300x43.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_enable_REST-768x109.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_enable_REST.png 1249w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Back on the <em><strong>Tool configuration</strong></em> tab of your ADB instance, you&#8217;ll find the <strong>Public access URL</strong>. Copy it, this will be your <strong>connection string</strong> when using the API.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="788" height="141" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_connection_string.png" alt="" class="wp-image-38512" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_connection_string.png 788w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_connection_string-300x54.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2025/05/20250915_oracle_api_mongodb_01_connection_string-768x137.png 768w" sizes="auto, (max-width: 788px) 100vw, 788px" /></figure>



<h4 id="h-connection-string-example" class="wp-block-heading">Connection String Example</h4>



<p class="wp-block-paragraph">For this to work, you have to replace the user and password in the connection string. For instance, if your user is called <code>USER_DB</code>, and your password is <code>userpwd</code>, then you would use this connection string (without the brackets). Make sure to escape any special character in the password when doing so (see <a href="https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/mongo-using-oracle-database-api-mongodb.html#GUID-44088366-81BF-4090-A5CF-09E56BB2ACAB">documentation</a>).</p>



<pre class="wp-block-code"><code>mongodb://<strong>user_db:userpwd</strong>@A49E7CHE9B320E6-PCCVX8PAE2NZPVBQ.adb.eu-zurich-1.oraclecloudapps.com:27017/<strong>user_db</strong>?authMechanism=PLAIN&amp;authSource=$external&amp;ssl=true&amp;retryWrites=false&amp;loadBalanced=true'</code></pre>



<p class="wp-block-paragraph">Use this connection string with <code>mongosh</code> or any tool provided by MongoDB. With <code>mongosh</code>, you would connect with this command :</p>



<pre class="wp-block-code"><code>mongosh 'mongodb://user_db:userpwd@A49E7CHE9B320E6-PCCVX8PAE2NZPVBQ.adb.eu-zurich-1.oraclecloudapps.com:27017/adb_admin?authMechanism=PLAIN&amp;authSource=$external&amp;ssl=true&amp;retryWrites=false&amp;loadBalanced=true'</code></pre>



<p class="wp-block-paragraph">You are now connected to the Oracle ADB instance through the <code>mongosh</code> utility.</p>



<p class="wp-block-paragraph"></p>



<h2 id="h-viewing-oracle-tables-with-the-api" class="wp-block-heading">Viewing Oracle tables with the API</h2>



<p class="wp-block-paragraph">If you connect to an existing schema with tables, you will notice that running <code>show collections</code> (or <code>show tables</code>) doesn&#8217;t return anything. In Oracle 19c, only collections/tables created through the API appear in this list. Standard tables created with a <code>CREATE TABLE</code> SQL statement won&#8217;t be displayed.</p>



<p class="wp-block-paragraph"></p>



<h2 id="h-included-and-excluded-features-in-the-api" class="wp-block-heading">Included and excluded features in the API</h2>



<p class="wp-block-paragraph">Once connected, you can query the different databases (schemas, in Oracle terms) of your instance. However, unlike in MongoDB, <strong>you can&#8217;t administer the instance</strong> through <code>mongosh</code>.</p>



<p class="wp-block-paragraph">You can look at the <a href="https://docs.oracle.com/en/database/oracle/mongodb-api/mgapi/support-mongodb-apis-operations-and-data-types-reference.html#GUID-B3751279-CA07-4809-BB84-78F09A76CAD9">documentation</a> to check the features included in the API, but here is an extract of the most notable changes :</p>



<ul class="wp-block-list">
<li>All the most basic <strong>aggregated pipelines</strong> are available in the API, but more complex ones like <code>$currentOp</code> or <code>$merge</code> are not yet supported.</li>



<li>Other aggregation operators, like <code>$bucket</code>, <code>$documents</code> or <code>$sample</code> are only available <strong>starting with Oracle 23ai</strong>.</li>



<li><code>db.dropDatabase()</code> doesn&#8217;t drop the Oracle schema. In fact, it doesn&#8217;t even delete everything in the schema. It only deletes all <em>real</em> collections inside of it. So if you have a traditional table that is not considered as a collection (not shown in <code>show collections</code>), it will not be deleted by this command.</li>
</ul>



<p class="wp-block-paragraph"></p>



<h2 id="h-troubleshooting-mongoservererror-database-connection-unavailable" class="wp-block-heading">Troubleshooting <code>MongoServerError: Database connection unavailable</code></h2>



<p class="wp-block-paragraph">You might encounter the following error :</p>



<pre class="wp-block-code"><code>MongoServerError: Database connection unavailable.&nbsp;Ensure that the user exists and the schema is enabled for use with Oracle REST Data Services. A schema can be enabled by calling the PL/SQL procedure ORDS.ENABLE_SCHEMA</code></pre>



<p class="wp-block-paragraph">If you see this message, you can either follow the procedure or remember to enable REST directly on the OCI <strong><em>Database Actions</em></strong> panel, as shown above.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">In short, <strong>Oracle&#8217;s MongoDB API</strong> provides an interesting bridge between the relational and document worlds. Even though some MongoDB features are not supported yet, the API offers a straightforward way to connect MongoDB and Oracle Autonomous Database. It makes it <strong>ideal for testing, for migration or even for hybrid setups</strong>. For developers used to MQL, it can significantly ease the transition to Oracle&#8217;s ecosystem.</p>
<p>L’article <a href="https://www.dbi-services.com/blog/using-oracle-api-for-mongodb-on-oci/">Using Oracle API for MongoDB on OCI</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/using-oracle-api-for-mongodb-on-oci/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MongoDB Log Analysis : A Comprehensive Guide</title>
		<link>https://www.dbi-services.com/blog/mongodb-log-analysis-a-comprehensive-guide/</link>
					<comments>https://www.dbi-services.com/blog/mongodb-log-analysis-a-comprehensive-guide/#respond</comments>
		
		<dc:creator><![CDATA[Julien Delattre]]></dc:creator>
		<pubDate>Fri, 10 Oct 2025 06:00:00 +0000</pubDate>
				<category><![CDATA[Database Administration & Monitoring]]></category>
		<category><![CDATA[Development & Performance]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[analysis]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[jq]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[metrics]]></category>
		<category><![CDATA[Mongo]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[slow queries]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=37497</guid>

					<description><![CDATA[<p>Contrary to other DBMS, MongoDB self-managed deployments generate logs in a JSON format, which can be quite intimidating at first. But instead of hoping to never have to look at the logs, you can use some tools and tips to navigate them more easily and not waste time finding the information you&#8217;re looking for. Log [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-log-analysis-a-comprehensive-guide/">MongoDB Log Analysis : A Comprehensive Guide</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Contrary to other DBMS, <strong><a href="https://www.dbi-services.com/technologies/mongodb/" target="_blank" rel="noreferrer noopener">MongoDB</a></strong> self-managed deployments generate <strong>logs in a JSON format</strong>, which can be quite intimidating at first. But instead of hoping to never have to look at the logs, you can use some <strong>tools and tips to navigate them</strong> more easily and not waste time finding the information you&#8217;re looking for.</p>



<div class="wp-block-yoast-seo-table-of-contents yoast-table-of-contents"><h2>Table of contents</h2><ul><li><a href="#log-format-overview" data-level="2">Log format overview</a></li><li><a href="#querying-logs-with-mongosh" data-level="2">Querying logs through mongosh</a></li><li><a href="#navigating-logs-with-jq" data-level="2">Navigating through the logs with jq</a></li><li><a href="#h-analyzing-slow-queries-with-jq" data-level="2">Analyzing slow queries with jq</a></li><li><a href="#h-mongodb-log-jq-query-builder" data-level="2">MongoDB log jq query builder</a></li><li><a href="#h-conclusion" data-level="2">Conclusion</a></li></ul></div>



<h2 id="log-format-overview" class="wp-block-heading">Log format overview</h2>



<p class="wp-block-paragraph">Inside <code>/var/log/mongodb/mongod.log</code> (or a custom path if you set one), a typical log entry looks like this (shortened, for readability) :</p>



<pre class="wp-block-code"><code>{"t":{"$date":"2025-03-06T14:54:28.298+01:00"},"s":"I",&nbsp; "c":"CONTROL",&nbsp; "id":8423403, "ctx":"initandlisten","msg":"mongod startup complete","attr":{"Summary of time elapsed":{"Startup from clean shutdown?":false,"Statistics":{"Set up periodic runner":"0 ms","Set up online certificate status protocol manager":"0 ms",&#091;...],"Start transport layer":"0 ms","_initAndListen total elapsed time":"626 ms"}}}}</code></pre>



<p class="wp-block-paragraph">At first glance, it&#8217;s pretty difficult to extract the essential information, but let&#8217;s see how the document looks like when it&#8217;s formatted (we&#8217;ll see how to do that later).</p>



<pre class="wp-block-code"><code>{
&nbsp; "t": {
&nbsp;&nbsp;&nbsp; "$date": "2025-03-06T14:54:28.298+01:00"
&nbsp; },
&nbsp; "s": "I",
&nbsp; "c": "CONTROL",
&nbsp; "id": 8423403,
&nbsp; "ctx": "initandlisten",
&nbsp; "msg": "mongod startup complete",
&nbsp; "attr": {
&nbsp;&nbsp;&nbsp; "Summary of time elapsed": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Startup from clean shutdown?": false,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Statistics": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Set up periodic runner": "0 ms",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Set up online certificate status protocol manager": "0 ms",
        &#091;...] # lines hidden
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Start transport layer": "0 ms",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "_initAndListen total elapsed time": "626 ms"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
&nbsp; }
}</code></pre>



<p class="wp-block-paragraph">Here is a description of the main fields of the log document :</p>



<ul class="wp-block-list">
<li><code>t</code> : Timestamp of the log entry.</li>



<li><code>s</code> : Severity code associated with the log entry (<code>E</code> for error, <code>W</code> for warning, <code>I</code> for information and <code>D1</code> to <code>D5</code> for debug).</li>



<li><code>c</code> : Category of the log entry. Most common categories are <code>CONTROL</code>, <code>COMMAND</code>, <code>ELECTION</code>, <code>REPL</code> (for replication) or <code>NETWORK</code>. An extensive list is available in the <a href="https://www.mongodb.com/docs/manual/reference/log-messages" target="_blank" rel="noreferrer noopener">official MongoDB documentation</a>.</li>



<li><code>id</code> : Unique log entry ID.</li>



<li><code>ctx</code> : Thread that generated the log.</li>



<li><code>msg</code> : Usually a short message describing the log.</li>



<li><code>attr</code> : Optional additional attributes.</li>
</ul>



<p class="wp-block-paragraph">This will help us when looking at the logs, first with <code>mongosh</code>.</p>



<h2 id="querying-logs-with-mongosh" class="wp-block-heading">Querying logs through <code>mongosh</code></h2>



<p class="wp-block-paragraph">You can query logs inside the MongoDB shell called <code>mongosh</code>. To do so, use the <code>getLog</code> admin command :</p>



<pre class="wp-block-code"><code>db.adminCommand({ getLog: "global"}); // display all log entries</code></pre>



<p class="wp-block-paragraph">Another useful option is to view startup warnings, which will only display warning logs since last startup.</p>



<pre class="wp-block-code"><code>db.adminCommand({ getLog: "startupWarnings" }) // display startup warnings
{
&nbsp; totalLinesWritten: 2,
&nbsp; log: &#091;
&nbsp;&nbsp;&nbsp; '{"t":{"$date":"2025-03-07T08:32:41.005+01:00"},"s":"W",&nbsp; "c":"NETWORK",&nbsp; "id":5123300, "ctx":"initandlisten","msg":"vm.max_map_count is too low","attr":{"currentValue":65530,"recommendedMinimum":102400,"maxConns":51200},"tags":&#091;"startupWarnings"]}\n',
&nbsp;&nbsp;&nbsp; '{"t":{"$date":"2025-03-07T08:32:41.005+01:00"},"s":"W",&nbsp; "c":"CONTROL",&nbsp; "id":8386700, "ctx":"initandlisten","msg":"We suggest setting swappiness to 0 or 1, as swapping can cause performance problems.","attr":{"sysfsFile":"/proc/sys/vm/swappiness","currentValue":60},"tags":&#091;"startupWarnings"]}\n'
&nbsp; ],
&nbsp; ok: 1
}</code></pre>



<p class="wp-block-paragraph">Even though this can sometimes be useful, it requires <strong>authenticated access</strong> to the database, and it only works when the <code>mongod</code> <strong>process is running</strong>. You won&#8217;t be able to use this method when the database crashes, for instance. Moreover, the logs are difficult to read.</p>



<p class="wp-block-paragraph">Most of the time, you will be better served by the <code>jq</code> utility.</p>



<h2 id="navigating-logs-with-jq" class="wp-block-heading">Navigating through the logs with <code>jq</code></h2>



<p class="wp-block-paragraph"><a href="https://jqlang.org/manual/" target="_blank" rel="noreferrer noopener"><code>jq</code></a> is a <strong>powerful utility</strong> that helps you navigate JSON documents, and even though it is not an official MongoDB product, you should <strong>always integrate</strong> it in your MongoDB deployments.</p>



<h4 id="h-prettify-mongodb-logs" class="wp-block-heading">Prettify MongoDB logs</h4>



<p class="wp-block-paragraph">The first benefit of the <code>jq</code> command is to display MongoDB logs in a readable format :</p>



<pre class="wp-block-code"><code>&gt; head -1 mongod.log | jq
{
&nbsp; "t": {
&nbsp;&nbsp;&nbsp; "$date": "2025-03-05T14:44:28.531+01:00"
&nbsp; },
&nbsp; "s": "I",
&nbsp; "c": "CONTROL",
&nbsp; "id": 23285,
&nbsp; "ctx": "main",
&nbsp; "msg": "Automatically disabling TLS 1.0"
}</code></pre>



<p class="wp-block-paragraph">Of course, a single line of log will now span multiple lines in the output. But thanks to the log structure explained above, we can write our first queries with <code>jq</code> to filter the results and only display what&#8217;s important.</p>



<p class="wp-block-paragraph">I would definitely recommend to <strong>build aliases</strong> with the following commands in order to quickly access the information that you find more valuable in the logs.</p>



<h4 id="h-display-error-messages" class="wp-block-heading"><strong>Display error messages</strong></h4>



<p class="wp-block-paragraph">By using the <code>s</code> field (severity), we can filter the logs to only display error messages. This is especially useful when failing to start a MongoDB instance.</p>



<pre class="wp-block-code"><code>jq 'select(.s == "E")' mongod.log</code></pre>



<p class="wp-block-paragraph">You can also include warnings by slightly modifying the command.</p>



<pre class="wp-block-code"><code>jq 'select(.s == "E" or .s == "W")' mongod.log</code></pre>



<h4 id="h-filtering-displayed-fields" class="wp-block-heading"><strong>Filtering displayed fields</strong></h4>



<p class="wp-block-paragraph">When selecting fields, you should pipe the <code>jq</code> filtering to a JSON object like this one :</p>



<pre class="wp-block-code"><code>{time: .t&#091;"$date"], message: .msg, error: .attr.error}</code></pre>



<p class="wp-block-paragraph">From now on, I will use the <code>-c</code> option to display the JSON in the compact format. Even in this format, logs can be readable when you select or exclude specific fields. Here, I want to select the <code>.t["$date"]</code>, <code>.msg</code> and <code>.attr.error</code> fields. To improve the display, I will rename them :</p>



<pre class="wp-block-code"><code>&gt; jq -c 'select(.s == "E") | {time: .t&#091;"$date"], message: .msg, error: .attr.error}' mongod.log
{"time":"2025-03-05T14:44:28.665+01:00","message":"WiredTiger error message","error":13}
{"time":"2025-03-05T14:44:28.665+01:00","message":"WiredTiger error message","error":13}
{"time":"2025-03-05T14:44:28.665+01:00","message":"WiredTiger error message","error":13}
{"time":"2025-03-06T10:17:07.383+01:00","message":"DBException in initAndListen, terminating","error":"Location28596: Unable to determine status of lock file in the data directory /var/lib/mongodb: boost::filesystem::status: Permission denied &#091;system:13]: \"/var/lib/mongodb/mongod.lock\""}</code></pre>



<p class="wp-block-paragraph">Similarly, you can exclude a field with the <code>del</code> function. For instance, this will remove the <code>message</code> sub-field located inside the <code>attr</code> field.</p>



<pre class="wp-block-code"><code>jq 'del(.attr.message)' mongod.log</code></pre>



<h4 id="h-errors-and-warnings-grouped-by-message" class="wp-block-heading"><strong>Errors and warnings grouped by message</strong></h4>



<p class="wp-block-paragraph">To check for recurrent warnings or errors, you can pipe the <code>jq</code> output to group the results by <code>msg</code> content.</p>



<pre class="wp-block-code"><code>jq 'select(.s == "E" or .s=="W") | .msg' mongod.log | sort | uniq -c | sort -nr | head</code></pre>



<h4 id="h-occurrences-of-each-log-severity" class="wp-block-heading"><strong>Occurrences of each log severity</strong></h4>



<p class="wp-block-paragraph">If you want to quickly look for the number of every severity, you can do so with the <code>s</code> field.</p>



<pre class="wp-block-code"><code>&gt; jq '.s' mongod.log | sort | uniq -c
&nbsp;&nbsp;&nbsp;&nbsp; 10 "E"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 "F"
&nbsp;&nbsp; 1727 "I"
     88 "W"</code></pre>



<h4 id="h-view-logs-for-specific-log-categories" class="wp-block-heading"><strong>View logs for specific log categories</strong></h4>



<p class="wp-block-paragraph">As mentioned before, the category of the logs might be interesting to filter (only the replication logs, for instance).</p>



<pre class="wp-block-code"><code>jq -c 'select(.c == "REPL")' mongod.log</code></pre>



<h4 id="h-filter-logs-by-date" class="wp-block-heading"><strong>Filter logs by date</strong></h4>



<p class="wp-block-paragraph">Whether you use log rotation or not, you might want to quickly access the last minutes/hours/days of logs. With the <code>date</code> utility, you can retrieve the most recent logs :</p>



<pre class="wp-block-code"><code>jq -c --arg since "$(date -d '10 minutes ago' +%Y-%m-%dT%H:%M:%S)" 'select(.t&#091;"$date"] &gt;= $since)' mongod.log</code></pre>



<p class="wp-block-paragraph">Still filtering on the <code>.t["$date"]</code> field, you can also extract a portion of the logs :</p>



<pre class="wp-block-code"><code>jq -c 'select(.t&#091;"$date"] &gt;= "2025-03-06T14:30:00" and .t&#091;"$date"] &lt;= "2025-03-06T14:40:00")' mongod.log</code></pre>



<h4 id="h-look-for-a-specific-pattern-in-the-log" class="wp-block-heading"><strong>Look for a specific pattern in the log</strong></h4>



<p class="wp-block-paragraph">Of course, you can always use <code>grep</code> followed by <code>jq</code> to find a pattern in the logs : <kbd>grep -i "pattern" mongod.log | jq</kbd></p>



<p class="wp-block-paragraph">But if you want to look for a specific pattern inside a specific field, you can do so with the <code>test</code> function :</p>



<pre class="wp-block-code"><code>&gt; jq -c 'select(.msg | test("failed to authenticate"; "i"))' mongod.log // (i option for case insensitivity)
{"t":{"$date":"2025-03-07T08:37:52.950+01:00"},"s":"I","c":"ACCESS","id":5286307,"ctx":"conn18","msg":"Failed to authenticate","attr":{"client":"xxx.xxx.xxx.xxx(ip):xxxxx(port)","isSpeculative":true,"isClusterMember":false,"mechanism":"SCRAM-SHA-256","user":"root","db":"admin","error":"AuthenticationFailed: SCRAM authentication failed, storedKey mismatch","result":18,"metrics":{"conversation_duration":{"micros":5091,"summary":{"0":{"step":1,"step_total":2,"duration_micros":62},"1":{"step":2,"step_total":2,"duration_micros":48}}}},"extraInfo":{}}}</code></pre>



<h4 id="h-check-for-logs-regarding-connections-to-the-mongodb-database" class="wp-block-heading"><strong>Check for logs regarding connections to the MongoDB database</strong></h4>



<p class="wp-block-paragraph">For filtering connections logs, search for the <code>attr.remote</code> field :</p>



<pre class="wp-block-code"><code>jq -c 'select(.attr.remote)' mongod.log</code></pre>



<h2 id="h-analyzing-slow-queries-with-jq" class="wp-block-heading">Analyzing slow queries with <code>jq</code></h2>



<p class="wp-block-paragraph">Inside the Mongo shell, you can activate logging for slow queries with <code>db.setProfilingLevel(1, &lt;slowms&gt;)</code>, with <code>&lt;slowms&gt;</code> being the threshold (in milliseconds) to log such queries.</p>



<p class="wp-block-paragraph"><strong>Warnings</strong> related to slow queries in MongoDB :</p>



<ul class="wp-block-list">
<li>Once activated, the slow queries logging could <strong>slow down the database</strong>, so be very careful when activating it.</li>



<li>There is a <strong>security threat</strong> when combining slow query logging and <strong>queryable encryption</strong>, since queries will not be encrypted in the <code>mongod.log</code> file.</li>
</ul>



<p class="wp-block-paragraph">Slow query logs look like this :</p>



<pre class="wp-block-code"><code>{
&nbsp; "t": { "$date": "2024-03-06T12:34:56.789Z" },
&nbsp; "s": "I",
&nbsp; "c": "COMMAND",
&nbsp; "id": 123,
&nbsp; "ctx": "conn20",
&nbsp; "msg": "Slow query",
&nbsp; "attr": {
&nbsp;&nbsp;&nbsp; "ns": "mydb.coll",
&nbsp;&nbsp;&nbsp; "command": { "find": "coll", "filter": { "status": "active" } },
&nbsp;&nbsp;&nbsp; "planSummary": "COLLSCAN",
&nbsp;&nbsp;&nbsp; "keysExamined": 0,
&nbsp;&nbsp;&nbsp; "docsExamined": 5000,
&nbsp;&nbsp;&nbsp; "numYields": 0,
&nbsp;&nbsp;&nbsp; "reslen": 2000,
&nbsp;&nbsp;&nbsp; "locks": { "Global": { "acquireCount": { "r": 1 } } },
&nbsp;&nbsp;&nbsp; "durationMillis": 150
&nbsp; }
}</code></pre>



<p class="wp-block-paragraph">With this in mind, and with what we have already seen, you can filter the logs with the fields you want, like <code>attr.durationMillis</code> (duration of the query, in milliseconds), or <code>attr.ns</code>, which is the object on which the query is made.</p>



<p class="wp-block-paragraph">For instance, if you want to retrieve slow queries above a given threshold (one second, in the example below) :</p>



<pre class="wp-block-code"><code>jq 'select(.attr.durationMillis &gt;= 1000)' mongod.log</code></pre>



<p class="wp-block-paragraph">Or if you want to filter slow queries on a specific database <code>mydb</code> and collection <code>coll</code> :</p>



<pre class="wp-block-code"><code>jq 'select(.msg == "Slow query" and .attr.ns == "mydb.coll")' mongod.log</code></pre>



<p class="wp-block-paragraph">You can also select only queries that are run on a given database <code>mydb</code> :</p>



<pre class="wp-block-code"><code>jq 'select(.msg == "Slow query" and .attr.command&#091;"$db"] == "mydb")' mongod.log
</code></pre>



<h2 id="h-mongodb-log-jq-query-builder" class="wp-block-heading">MongoDB log <code>jq</code> query builder</h2>



<p class="wp-block-paragraph">On my <a href="https://juliendelattre.com/tools/mongodb-log-jq-builder/" target="_blank" rel="noreferrer noopener">personal blog</a>, I designed a tool for MongoDB log analysis with jq. Feel free to check it out !</p>



<h2 id="h-conclusion" class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">While being a bit complex at first sight, MongoDB logs are very useful if you know how to apprehend them. By leveraging the <code>jq</code> utility for advanced filtering, and combining it with monitoring tools, you can efficiently analyze logs and improve your efficiency as a DBA.</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-log-analysis-a-comprehensive-guide/">MongoDB Log Analysis : A Comprehensive Guide</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/mongodb-log-analysis-a-comprehensive-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Redis: Redis X Grafana fix the &#8220;get instance error&#8221; message</title>
		<link>https://www.dbi-services.com/blog/redis-redis-x-grafana-fix-the-get-instance-error-message/</link>
					<comments>https://www.dbi-services.com/blog/redis-redis-x-grafana-fix-the-get-instance-error-message/#comments</comments>
		
		<dc:creator><![CDATA[Middleware Team]]></dc:creator>
		<pubDate>Fri, 03 Nov 2023 16:59:34 +0000</pubDate>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Grafana]]></category>
		<category><![CDATA[Redis]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=29143</guid>

					<description><![CDATA[<p>Introduction Last time, we have seen how to add a Redis plugin to Grafana in order to monitor and generate graphs and charts for your reports or analysis. During this configuration you may encounter some issues or miss some steps that will end to an error message. Today we will see some typical error message [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/redis-redis-x-grafana-fix-the-get-instance-error-message/">Redis: Redis X Grafana fix the &#8220;get instance error&#8221; message</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="h-introduction">Introduction</h2>



<p class="wp-block-paragraph">Last time, we have seen how to add a Redis plugin to Grafana in order to monitor and generate graphs and charts for your reports or analysis.</p>



<p class="wp-block-paragraph">During this configuration you may encounter some issues or miss some steps that will end to an error message.</p>



<p class="wp-block-paragraph">Today we will see some typical error message and who to fix it quickly.</p>



<h2 class="wp-block-heading" id="h-check-if-your-plugin-s-version-installed-on-grafana">Check if your plugin&#8217;s version installed on Grafana</h2>



<p class="wp-block-paragraph">First step is to have confirmation that your Redis plugin is installed and up to date.</p>



<ul class="wp-block-list">
<li>Go to Administration then Plugins</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="387" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER5-1024x387.png" alt="" class="wp-image-29146" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER5-1024x387.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER5-300x113.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER5-768x290.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER5-1536x581.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER5.png 1899w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Check if plugin is here </li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="397" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER6-1024x397.png" alt="" class="wp-image-29147" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER6-1024x397.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER6-300x116.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER6-768x298.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER6-1536x595.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER6.png 1897w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>As you see, plugin is here and installed</li>
</ul>



<ul class="wp-block-list">
<li>Check the plugin version ( in case you are not able to debug it it may be useful for Redis support team )</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="460" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER7-1024x460.png" alt="" class="wp-image-29148" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER7-1024x460.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER7-300x135.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER7-768x345.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER7-1536x690.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER7.png 1895w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Now you have the plugin version and also its compatibility with the Grafana version</p>



<p class="wp-block-paragraph">( in our example it is compatible with Grafana versions &gt; +8.0.0 )</p>



<p class="wp-block-paragraph">If all is fine at this level, we can now focus on the different error messages related to Redis instance.</p>



<h2 class="wp-block-heading" id="h-fix-getinstance-error-connection-refused">Fix getInstance error: connection refused</h2>



<p class="wp-block-paragraph">When you connect to Grafana, you have to define the Redis database:</p>



<ul class="wp-block-list">
<li>Go to Home Connections=&gt;Data sources</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="369" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER12-1024x369.png" alt="" class="wp-image-29151" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER12-1024x369.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER12-300x108.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER12-768x277.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER12-1536x554.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER12.png 1898w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>When adding all your database details and you click on &#8220;save and test&#8221; button, your can face the famous issue</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="439" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER_1st_issue_ip-1024x439.png" alt="" class="wp-image-29152" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER_1st_issue_ip-1024x439.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER_1st_issue_ip-300x129.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER_1st_issue_ip-768x329.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER_1st_issue_ip-1536x659.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER_1st_issue_ip.png 1895w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">For this specific case it can simply due to the fact that your Redis database is not up!</p>



<p class="wp-block-paragraph">So check that in priority.</p>



<ul class="wp-block-list">
<li>If it is not UP, then start it and retry the &#8220;Save and test&#8221; option</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="496" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER20debugredisstart-1024x496.png" alt="" class="wp-image-29153" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER20debugredisstart-1024x496.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER20debugredisstart-300x145.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER20debugredisstart-768x372.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER20debugredisstart-1536x743.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER20debugredisstart.png 1903w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Use the redis-server command or start the Redis service using systemd on your Redis server:</li>
</ul>



<pre class="wp-block-code"><code>nso@DBI-LT-NSO:~&gt; redis-server</code></pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="556" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-6-1024x556.png" alt="" class="wp-image-29190" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-6-1024x556.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-6-300x163.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-6-768x417.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-6-1536x835.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-6.png 1903w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph"><span style="text-decoration: underline">Example on Linux:</span></p>



<pre class="wp-block-code"><code>sudo systemctl start redis.service</code></pre>



<ul class="wp-block-list">
<li>If you are in that specific case it should work fine now <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></li>
</ul>



<ul class="wp-block-list">
<li>The second case can be because your address is not correctly set or not recognized</li>
</ul>



<p class="wp-block-paragraph">Below my local host name didn&#8217;t worked:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="954" height="321" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-7.png" alt="" class="wp-image-29193" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-7.png 954w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-7-300x101.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-7-768x258.png 768w" sizes="auto, (max-width: 954px) 100vw, 954px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="370" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-8-1024x370.png" alt="" class="wp-image-29194" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-8-1024x370.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-8-300x109.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-8-768x278.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-8-1536x556.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-8.png 1874w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>So for those using a Docker image like me we must add the docker host IP address  instead.</li>
</ul>



<h2 class="wp-block-heading" id="h-get-the-docker-host-ip-address">Get the docker host IP Address </h2>



<p class="wp-block-paragraph">To get the docker ip address use the following commands:</p>



<pre class="wp-block-code"><code>docker inspect &lt;containerNameOrId&gt;</code></pre>



<p class="wp-block-paragraph"><span style="text-decoration: underline">Example:</span></p>



<pre class="wp-block-code"><code>C:\WINDOWS\system32&gt;docker inspect </code></pre>



<pre class="wp-block-code"><code>8c6c36853ab0490ecca607a6aa28bd158f8f798fd221c24f973faf33be7dfb23</code></pre>



<p class="wp-block-paragraph">You can then pick the Docker ip address</p>



<p class="wp-block-paragraph">Here in my example it is 172.17.0.2</p>



<p class="wp-block-paragraph">&#8220;Usually, the default docker ip range is <code>172.17.0.0/16</code>. </p>



<p class="wp-block-paragraph">Your host should be <code>172.17.0.1</code> and your first container should be <code>172.17.0.2</code> if everything is normal and you didn&#8217;t specify any special network options.&#8221;</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="182" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-9-1024x182.png" alt="" class="wp-image-29198" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-9-1024x182.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-9-300x53.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-9-768x137.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-9-1536x274.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-9.png 1886w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Let&#8217;s try now:</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="452" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-10-1024x452.png" alt="" class="wp-image-29201" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-10-1024x452.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-10-300x132.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-10-768x339.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-10-1536x678.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-10.png 1864w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>If it is still not working with Docker IP address you picked by using the docker inspect command, use the following syntax:</li>
</ul>



<pre class="wp-block-code"><code>host.docker.internal: &lt;your_Redis_port&gt;</code></pre>



<p class="wp-block-paragraph"><span style="text-decoration: underline">Example:</span></p>



<pre class="wp-block-code"><code>host.docker.internal: 6379</code></pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="410" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-12-1024x410.png" alt="" class="wp-image-29204" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-12-1024x410.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-12-300x120.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-12-768x307.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-12-1536x615.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-12.png 1876w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">It should work now!</p>



<h2 class="wp-block-heading" id="h-fix-getinstance-error-err-auth">Fix getInstance error : ERR AUTH</h2>



<p class="wp-block-paragraph">This &#8220;error&#8221; message will display when you have not configured the default password user.</p>



<ul class="wp-block-list">
<li>So you know what to do as the error message is explicit ( check your configuration )</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="417" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-3-1024x417.png" alt="" class="wp-image-29155" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-3-1024x417.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-3-300x122.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-3-768x313.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-3-1536x625.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-3.png 1904w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Anyway, If you let the password part empty (click reset and remove the password) you can test with success</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="189" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-4-1024x189.png" alt="" class="wp-image-29157" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-4-1024x189.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-4-300x55.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-4-768x142.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-4.png 1519w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="h-fix-getinstance-error-denied">Fix getInstance error : DENIED</h2>



<ul class="wp-block-list">
<li>This specific message is more verbose,it propose you solution to fix it such as:</li>
</ul>



<p class="wp-block-paragraph">a)disable the protected mode by many ways</p>



<p class="wp-block-paragraph">b)setup a bind address or authentication by password</p>



<ul class="wp-block-list">
<li>Here are the different ways to disable the protected mode:</li>
</ul>



<p class="wp-block-paragraph">&#8220;DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions:</p>



<p class="wp-block-paragraph">1) Just disable protected mode sending the command &#8220;CONFIG SET protected-mode no&#8221; from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.</p>



<p class="wp-block-paragraph">2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to &#8216;no&#8217;, and then restarting the server.</p>



<p class="wp-block-paragraph">Go to your redis.cfg file and update the below line and set it to &#8220;no&#8221;</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="764" height="816" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-5.png" alt="" class="wp-image-29168" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-5.png 764w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/image-5-281x300.png 281w" sizes="auto, (max-width: 764px) 100vw, 764px" /></figure>



<p class="wp-block-paragraph">3) If you started the server manually just for testing, restart it with the &#8216;<strong>&#8211;protected-mode no</strong>&#8216; option.</p>



<p class="wp-block-paragraph">4) Setup a bind address or an authentication password.</p>



<p class="wp-block-paragraph">Of course : <strong>You only need to do one of the above things</strong> in order for the server to start accepting connections from the outside.</p>



<p class="wp-block-paragraph"><em>From Redis site</em></p>



<p class="wp-block-paragraph"><span style="text-decoration: underline">Example:</span></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="463" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER9-1024x463.png" alt="" class="wp-image-29158" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER9-1024x463.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER9-300x136.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER9-768x348.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER9-1536x695.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER9.png 1887w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>For our case we will disable protected mode as it is only for test purpose.</li>
</ul>



<ul class="wp-block-list">
<li>Use the below command on your Redis instance: </li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="953" height="539" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER10.png" alt="" class="wp-image-29160" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER10.png 953w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER10-300x170.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/11/RGDOCKER10-768x434.png 768w" sizes="auto, (max-width: 953px) 100vw, 953px" /></figure>



<ul class="wp-block-list">
<li>Now you can use the save and test option it should work</li>
</ul>



<h2 class="wp-block-heading" id="h-conclusion">Conclusion</h2>



<p class="wp-block-paragraph">Now you know how to fix the main issues when defining your Redis instance in Grafana.</p>



<p class="wp-block-paragraph">If you are still stuck, you can also check on <a href="https://grafana.com/">Grafana official site</a> database you can find some useful info.</p>



<p class="wp-block-paragraph">Feel free to check <a href="https://www.dbi-services.com/blog/author/nabilsaoual/page/5/">my other posts</a> and also the dbi bloggers.</p>



<p class="wp-block-paragraph">Next time we will see how to use Grafana with MongoDB.</p>



<p class="wp-block-paragraph">Stay tuned!</p>
<p>L’article <a href="https://www.dbi-services.com/blog/redis-redis-x-grafana-fix-the-get-instance-error-message/">Redis: Redis X Grafana fix the &#8220;get instance error&#8221; message</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/redis-redis-x-grafana-fix-the-get-instance-error-message/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Redis:Connect a Redis plugin to Grafana</title>
		<link>https://www.dbi-services.com/blog/redisconnect-a-redis-plugin-to-grafana/</link>
					<comments>https://www.dbi-services.com/blog/redisconnect-a-redis-plugin-to-grafana/#respond</comments>
		
		<dc:creator><![CDATA[Middleware Team]]></dc:creator>
		<pubDate>Thu, 26 Oct 2023 16:02:57 +0000</pubDate>
				<category><![CDATA[NoSQL]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=28790</guid>

					<description><![CDATA[<p>Introduction: Monitoring our Redis database is one of the first thing we want to do : Checking the database status , the queries consumption and also make a report on it. For that, we will use Grafana: It is an open source analytics &#38; monitoring solution for every database. Grafana can add some plugins to [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/redisconnect-a-redis-plugin-to-grafana/">Redis:Connect a Redis plugin to Grafana</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="h-introduction">Introduction:</h2>



<p class="wp-block-paragraph">Monitoring our Redis database is one of the first thing we want to do : Checking the database status , the queries consumption and also make a report on it.</p>



<p class="wp-block-paragraph">For that, we will use Grafana:</p>



<p class="wp-block-paragraph">It is an open source analytics &amp; monitoring solution for every database.</p>



<p class="wp-block-paragraph">Grafana can add some <strong>plugins </strong>to work on a specific database.I guess you have understood that the today&#8217;s topic is to add a Redis plugin to Grafana in order to have some dashboard and graphs.</p>



<h2 class="wp-block-heading" id="h-what-is-grafana">What is Grafana?</h2>



<p class="wp-block-paragraph">Grafana is a free software application licensed under the GNU Affero General Public License Version 32 (formerly under the Apache 2.0 license until April 2021)</p>



<p class="wp-block-paragraph">It enables data visualisation.</p>



<p class="wp-block-paragraph">It can be used to create dashboards and graphs from a number of sources, including temporal databases such as Graphite, InfluxDB and OpenTSDB.</p>



<h2 class="wp-block-heading" id="h-how-to-install-grafana">How to install Grafana</h2>



<p class="wp-block-paragraph">You have many ways to install this tool and it is supported on many operating systems:</p>



<p class="wp-block-paragraph">Below you will have the list of the operating systems ( I will probably make another post to go deeper in details )</p>



<ul class="wp-block-list">
<li>Debian or Ubuntu</li>



<li>RHEL or Fedora</li>



<li>SUSE or openSUSE</li>



<li>Grafana Docker image</li>



<li>Grafana on Kubernetes</li>



<li>macOS</li>



<li>Windows</li>
</ul>



<p class="wp-block-paragraph">As we have many installation choices, we will review that later in a incoming Blog.For this post I have chosen the <strong>Docker images method</strong>.</p>



<h2 class="wp-block-heading" id="h-run-grafana-docker-image">Run Grafana Docker image<a href="https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/#run-grafana-docker-image"></a></h2>



<p class="wp-block-paragraph">This installation will be made in two steps:</p>



<ul class="wp-block-list">
<li>We will see how to install the Grafana image on Docker</li>
</ul>



<ul class="wp-block-list">
<li>We will see how to add our famous Redis plugin ( it is possible to run directly the Grafana image containing also the Redis plugin! )</li>
</ul>



<h2 class="wp-block-heading" id="h-grafana-docker-image">Grafana docker image</h2>



<p class="wp-block-paragraph">Grafana Docker images come in two editions:</p>



<ul class="wp-block-list">
<li><strong>Grafana Enterprise</strong>: <code>grafana/grafana-enterprise</code></li>



<li><strong>Grafana Open Source</strong>: <code>grafana/grafana-oss</code></li>
</ul>



<p class="wp-block-paragraph">For my case I have chosen the Grafana Open source Image</p>



<h2 class="wp-block-heading" id="h-docker-useful-commands-for-your-grafana-container">Docker useful commands for your grafana container</h2>



<ul class="wp-block-list">
<li>Run Grafana via Docker CLI<a href="https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/#run-grafana-via-docker-cli"></a></li>
</ul>



<p class="wp-block-paragraph">To run the latest stable version of Grafana, run the following command:</p>



<pre class="wp-block-code"><code>docker run -d -p 3000:3000 --name=grafana grafana/grafana-enterprise</code></pre>



<pre class="wp-block-code"><code>docker run -d -p 3000:3000 --name=grafana grafana/grafana-oss</code></pre>



<ul class="wp-block-list">
<li>Stop the Grafana container</li>
</ul>



<p class="wp-block-paragraph">Use the <code>docker ps</code> command to show  the processes running in Docker:</p>



<pre class="wp-block-code"><code>C:\Users\nso&gt;docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5fede37b3da grafana/grafana-oss "/run.sh" 8 seconds ago Up 8 seconds 0.0.0.0:3000-&gt;3000/tcp grafana</code></pre>



<p class="wp-block-paragraph">To stop the container use the command docker stop:</p>



<ul class="wp-block-list">
<li>docker stop CONTAINER-ID or use</li>



<li>docker stop NAME, here it is <code>grafana</code> as previously defined</li>
</ul>



<pre class="wp-block-code"><code>C:\Users\nso&gt;docker stop grafana

grafana</code></pre>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="84" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-23-1024x84.png" alt="" class="wp-image-28805" style="aspect-ratio:12.19047619047619;width:1041px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-23-1024x84.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-23-300x25.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-23-768x63.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-23.png 1403w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="h-additional-docker-recommended-actions">Additional docker recommended actions</h2>



<p class="wp-block-paragraph">Additional actions are recommended ( we will not describe it now but it can be a topic for next time ) such as:</p>



<ul class="wp-block-list">
<li>Save your Grafana data</li>



<li>Use Docker volumes</li>



<li>Use bind mounts<a href="https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/#use-bind-mounts"></a></li>



<li>Use environment variables to configure Grafana<a href="https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/#use-environment-variables-to-configure-grafana"></a></li>
</ul>



<h2 class="wp-block-heading" id="h-run-grafana-image-with-the-redis-plugin">Run Grafana image with the Redis plugin</h2>



<h3 class="wp-block-heading" id="h-install-plugins-in-the-docker-container">Install plugins in the Docker container<a href="https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/#install-plugins-in-the-docker-container"></a></h3>



<p class="wp-block-paragraph">&#8220;You can install plugins in Grafana from the official and community <a href="https://grafana.com/grafana/plugins">plugins page</a> or by using a custom URL to install a private plugin.</p>



<p class="wp-block-paragraph">These plugins allow you to add new visualization types, data sources, and applications to help you better visualize your data.&#8221; </p>



<p class="wp-block-paragraph">Grafana currently supports three types of plugins: panel, data source, and app.</p>



<p class="wp-block-paragraph">For more information on managing plugins, refer to <a href="https://grafana.com/docs/grafana/latest/administration/plugin-management/">Plugin Management</a>.</p>



<p class="wp-block-paragraph">Extract from <a href="https://grafana.com/">grafana </a>official site</p>



<h3 class="wp-block-heading" id="h-about-redis-plugin">About Redis plugin</h3>



<p class="wp-block-paragraph">The Redis Data Source for Grafana allows users to connect to any Redis database On-Premises and in the Cloud.</p>



<p class="wp-block-paragraph">It provides out-of-the-box predefined dashboards and lets you build customized dashboards to monitor Redis and application data.</p>



<h3 class="wp-block-heading" id="h-redis-plugin-requirements">Redis plugin requirements </h3>



<ul class="wp-block-list">
<li><strong>Grafana 8.0+</strong> is required for Redis Data Source 2.X.</li>



<li><strong>Grafana 7.1+</strong> is required for Redis Data Source 1.X.</li>
</ul>



<h3 class="wp-block-heading">Redis Application plugin</h3>



<p class="wp-block-paragraph">You can add as many data sources as you want to support multiple Redis databases. <a href="https://grafana.com/grafana/plugins/redis-app" target="_blank" rel="noreferrer noopener">Redis Application plugin</a> helps manage various Redis Data Sources and provides Custom panels.</p>



<h3 class="wp-block-heading">Redis Explorer plugin</h3>



<p class="wp-block-paragraph"><a href="https://grafana.com/grafana/plugins/redis-explorer-app" target="_blank" rel="noreferrer noopener">The Redis Explorer plugin</a> connects to Redis Enterprise software clusters using REST API. It provides application pages to add Redis Data Sources for managed databases and dashboards to see cluster configuration.</p>



<h2 class="wp-block-heading" id="h-run-the-redis-plugin">Run the Redis plugin</h2>



<p class="wp-block-paragraph">Use the following command to run the Grafana image with the Redis plugins inside:</p>



<pre class="wp-block-code"><code>C:\Users\nso&gt;docker run -d -p 3000:3000 --name=grafana -e "GF_INSTALL_PLUGINS=redis-datasource" grafana/grafana-oss</code></pre>



<p class="wp-block-paragraph">Here we have added the plugin name &#8221; redis-datasource&#8221; to the image &#8220;grafana-oss&#8221;</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="141" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER1-1024x141.png" alt="" class="wp-image-28815" style="aspect-ratio:7.26241134751773;width:984px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER1-1024x141.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER1-300x41.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER1-768x106.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER1-1536x211.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER1.png 1899w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="h-open-grafana">Open Grafana</h2>



<p class="wp-block-paragraph">Now you have launched the Garfana image, we will check if the plugin is here:</p>



<ul class="wp-block-list">
<li>Open an url to your address using port 3000</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="465" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER2-1024x465.png" alt="" class="wp-image-28819" style="aspect-ratio:2.2021505376344086;width:1025px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER2-1024x465.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER2-300x136.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER2-768x348.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER2-1536x697.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER2.png 1898w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Enter the default  user and password ( admin , admin )</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="435" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER3-1024x435.png" alt="" class="wp-image-28820" style="aspect-ratio:2.354022988505747;width:1020px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER3-1024x435.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER3-300x128.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER3-768x327.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER3-1536x653.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER3.png 1893w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>When done it will be asked you to update the password for security matters</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="679" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-24-1024x679.png" alt="" class="wp-image-28829" style="aspect-ratio:1.508100147275405;width:1006px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-24-1024x679.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-24-300x199.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-24-768x509.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-24.png 1232w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="h-connect-your-database">Connect your database</h2>



<ul class="wp-block-list">
<li>On Grafana select <strong>home/connections/data sources</strong></li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="462" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER11-1024x462.png" alt="" class="wp-image-28827" style="aspect-ratio:2.2164502164502164;width:1041px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER11-1024x462.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER11-300x135.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER11-768x347.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER11-1536x693.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER11.png 1899w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="h-configure-your-redis-plugin">Configure your Redis plugin </h2>



<ul class="wp-block-list">
<li>Go to <strong>home/administration/plugins </strong></li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="397" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER6-1024x397.png" alt="" class="wp-image-28831" style="aspect-ratio:2.579345088161209;width:1028px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER6-1024x397.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER6-300x116.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER6-768x298.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER6-1536x595.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER6.png 1897w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">We see that some plugins are installed by default and other can be added , here Redis plugin installed and signed.We will open it and see what it is possible to do with it.</p>



<ul class="wp-block-list">
<li>Open Redis plugin</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="460" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER7-1024x460.png" alt="" class="wp-image-28832" style="aspect-ratio:2.226086956521739;width:1027px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER7-1024x460.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER7-300x135.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER7-768x345.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER7-1536x690.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER7.png 1895w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Add your data source</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="369" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER12-1024x369.png" alt="" class="wp-image-28837" style="aspect-ratio:2.7750677506775068;width:1023px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER12-1024x369.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER12-300x108.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER12-768x277.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER12-1536x554.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER12.png 1898w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>You have the choice to explore or to build a new dashboard, let&#8217;s try it</li>



<li>you have now the choice to add a visualization ( you are also able to import dashboard or add a library panel )</li>



<li>Go to Home/Dashboards/ New dashboard and select &#8220;Add visualization&#8221;</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="399" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER13-1024x399.png" alt="" class="wp-image-28839" style="aspect-ratio:2.5664160401002505;width:1011px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER13-1024x399.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER13-300x117.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER13-768x299.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER13-1536x599.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER13.png 1901w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Now we can chose how to display our results</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="493" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER14-1024x493.png" alt="" class="wp-image-28838" style="aspect-ratio:2.077079107505071;width:1018px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER14-1024x493.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER14-300x144.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER14-768x370.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER14-1536x740.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER14.png 1541w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Select the display for example time series, a table or a Bar chart</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="426" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER16-1024x426.png" alt="" class="wp-image-28840" style="aspect-ratio:2.403755868544601;width:1017px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER16-1024x426.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER16-300x125.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER16-768x319.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER16-1536x639.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER16.png 1885w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">In the command part, you can use the Redis commands to interact with your database and of course the related keys.</p>



<ul class="wp-block-list">
<li>Another example here with another display with a Gauge:</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="464" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-25-1024x464.png" alt="" class="wp-image-28841" style="aspect-ratio:2.206896551724138;width:1007px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-25-1024x464.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-25-300x136.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-25-768x348.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-25-1536x695.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-25.png 1891w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="h-save-your-dashboard">Save your dashboard</h2>



<ul class="wp-block-list">
<li>Once your dashboard is ready you click on apply and save</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="440" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER17save-1024x440.png" alt="" class="wp-image-28844" style="aspect-ratio:2.327272727272727;width:999px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER17save-1024x440.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER17save-300x129.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER17save-768x330.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER17save-1536x661.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER17save.png 1902w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Give a name to your dashboard and save it</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="386" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER18save-1024x386.png" alt="" class="wp-image-28845" style="aspect-ratio:2.6528497409326426;width:1001px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER18save-1024x386.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER18save-300x113.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER18save-768x289.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER18save-1536x579.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER18save.png 1866w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="h-load-your-dashboard">Load your dashboard</h2>



<p class="wp-block-paragraph">You can now load your presets and see your saved dashboards</p>



<ul class="wp-block-list">
<li>Go in home/dashboards </li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="300" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER19save-1024x300.png" alt="" class="wp-image-28847" style="aspect-ratio:3.4133333333333336;width:998px;height:auto" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER19save-1024x300.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER19save-300x88.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER19save-768x225.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER19save-1536x450.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/RGDOCKER19save.png 1899w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">That&#8217;s is you know how to create your own dashboard!</p>



<h2 class="wp-block-heading" id="h-conclusion">Conclusion </h2>



<p class="wp-block-paragraph">Now you know how to use Grafana to work with your Redis database.You can download the plugin by some other ways, we can see that another time if you need it.</p>



<p class="wp-block-paragraph">I hope you enjoyed this blog and you have tested it on your own side.</p>



<p class="wp-block-paragraph">I will prepare a troubleshooting post for this Grafana plugin installation in order to avoid you some issue I have faced <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p class="wp-block-paragraph">Stay tuned for next posts, you can also check my <a href="https://www.dbi-services.com/blog/author/nabilsaoual/page/5/">previous ones</a> and also the dbi bloggers.</p>



<p class="wp-block-paragraph">And of course don&#8217;t hesitate to take a look on the <a href="https://grafana.com/">Grafana official site</a> which is extremely well documented !</p>
<p>L’article <a href="https://www.dbi-services.com/blog/redisconnect-a-redis-plugin-to-grafana/">Redis:Connect a Redis plugin to Grafana</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/redisconnect-a-redis-plugin-to-grafana/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Redis: How transactions work in Redis</title>
		<link>https://www.dbi-services.com/blog/redis-how-transactions-work-in-redis/</link>
					<comments>https://www.dbi-services.com/blog/redis-how-transactions-work-in-redis/#respond</comments>
		
		<dc:creator><![CDATA[Middleware Team]]></dc:creator>
		<pubDate>Fri, 20 Oct 2023 16:37:39 +0000</pubDate>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Redis]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=28700</guid>

					<description><![CDATA[<p>Introduction: Redis allows you to use many commands to create and administrate your database. There is especially one useful feature which which allows you to execute a series of commands as a single unit of work: The Redis transactions! In this post will check how it works how it can be useful for your daily [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/redis-how-transactions-work-in-redis/">Redis: How transactions work in Redis</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="h-introduction">Introduction:</h2>



<p class="wp-block-paragraph">Redis allows you to use many commands to create and administrate your database.</p>



<p class="wp-block-paragraph">There is especially one useful feature which which allows you to execute a series of commands as a single unit of work:</p>



<p class="wp-block-paragraph">The Redis transactions!</p>



<p class="wp-block-paragraph">In this post will check how it works how it can be useful for your daily work.</p>



<h2 class="wp-block-heading" id="h-how-do-transactions-work">How do transactions work?</h2>



<p class="wp-block-paragraph">Transactions allows to send a block of commands, using the the <strong>MULTI </strong>command.</p>



<p class="wp-block-paragraph">All the commands will be queued the when using the EXEC command it will be executed.</p>



<p class="wp-block-paragraph">Note:</p>



<p class="wp-block-paragraph">A request sent by another client will never be served in the middle of the execution of a Redis Transaction. &#8220;<strong>This guarantees that the commands are executed as a single isolated operation</strong>&#8220;</p>



<p class="wp-block-paragraph">Here is a quick example :</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="617" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-13-1024x617.png" alt="" class="wp-image-28710" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-13-1024x617.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-13-300x181.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-13-768x463.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-13.png 1175w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">In a row, we created a key &#8220;PLAYERS&#8221; with the player name and their associated number, then we wanted it to be displayed using the command.</p>



<p class="wp-block-paragraph">The EXEC command will commit all these actions.</p>



<p class="wp-block-paragraph"><span style="text-decoration: underline"><strong>Note:</strong></span></p>



<p class="wp-block-paragraph">When using the <strong>MULTI </strong>command, the inputs are not executed until the <strong>EXEC </strong>command is done.</p>



<h2 class="wp-block-heading" id="h-what-are-the-benefits-of-redis-transactions">What are the benefits of Redis transactions?</h2>



<p class="wp-block-paragraph" id="c5c0">First one is that transactions are atomic. In other words all of the commands in the transaction are completed or none of them are. </p>



<p class="wp-block-paragraph" id="c5c0">This is an essential point for ensuring the consistency of your data, so that you don&#8217;t end up in a situation where certain commands in the transaction have been executed, but not others.</p>



<p class="wp-block-paragraph" id="a003">Other good point, transactions in Redis are very fast. </p>



<p class="wp-block-paragraph" id="a003">Remember Redis works as an in-memory database, it&#8217;s a reason it can execute transactions very quickly.</p>



<p class="wp-block-paragraph" id="a003">This makes it ideal for use cases where you need to make multiple changes to your data in a short period of time.</p>



<h2 class="wp-block-heading" id="what-about-rollbacks">Are rollbacks possible?</h2>



<p class="wp-block-paragraph">Unfortunately not, but there is a good reason:</p>



<p class="wp-block-paragraph">Supporting rollbacks would have a significant <strong>impact on the simplicity and performance</strong> of Redis.</p>



<h2 class="wp-block-heading" id="h-how-to-discard-a-transaction">How to discard a transaction?</h2>



<p class="wp-block-paragraph">You can use the <strong>DISCARD </strong>command to abort your transaction.</p>



<p class="wp-block-paragraph">After that all it will not execute the commands within the transaction and your data will be restored to normal.</p>



<p class="wp-block-paragraph"><strong>Here is an example:</strong></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="433" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-14-1024x433.png" alt="" class="wp-image-28722" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-14-1024x433.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-14-300x127.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-14-768x325.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-14-1536x649.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-14.png 1594w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>As you can see, the <strong>NUMBERS </strong>value remained the same 123456789</li>
</ul>



<h2 class="wp-block-heading" id="h-watch-command">Watch command </h2>



<p class="wp-block-paragraph">Watch main function is to monitor keys, this command  will make the <a href="https://redis.io/commands/exec"><code>EXEC</code></a> conditional:</p>



<p class="wp-block-paragraph">Following that principle, <a href="https://redis.io/commands/exec"><code>EXEC</code></a> performs the transaction <strong>on the key only if this key is not</strong> <a href="https://redis.io/commands/watch"><code>WATCH</code></a>ed </p>



<p class="wp-block-paragraph">This includes modifications made by the client, like write commands, and by Redis itself, like expiration or eviction. </p>



<p class="wp-block-paragraph">If keys were modified between when they were <a href="https://redis.io/commands/watch"><code>WATCH</code></a>ed and when the <a href="https://redis.io/commands/exec"><code>EXEC</code></a> was received, the entire transaction will be aborted instead.</p>



<p class="wp-block-paragraph"><strong>Below an example of watch command</strong>:</p>



<ul class="wp-block-list">
<li>1st user watch the key then start the transaction by updating the key value:</li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="956" height="256" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-20.png" alt="" class="wp-image-28747" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-20.png 956w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-20-300x80.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-20-768x206.png 768w" sizes="auto, (max-width: 956px) 100vw, 956px" /></figure>



<ul class="wp-block-list">
<li>In the mean time, the second user modifies the key with another value:</li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="955" height="140" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-16.png" alt="" class="wp-image-28742" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-16.png 955w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-16-300x44.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-16-768x113.png 768w" sizes="auto, (max-width: 955px) 100vw, 955px" /></figure>



<ul class="wp-block-list">
<li>When the 1st user issues the EXEC command, the result is an error:</li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="955" height="109" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-18.png" alt="" class="wp-image-28744" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-18.png 955w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-18-300x34.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-18-768x88.png 768w" sizes="auto, (max-width: 955px) 100vw, 955px" /></figure>



<ul class="wp-block-list">
<li>When we see the value of NUMBERS the modification was done by the 2nd user:</li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="955" height="231" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-19.png" alt="" class="wp-image-28746" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-19.png 955w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-19-300x73.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/10/image-19-768x186.png 768w" sizes="auto, (max-width: 955px) 100vw, 955px" /></figure>



<ul class="wp-block-list">
<li>You see now how the <strong>WATCH</strong> command prevents the <strong>EXEC</strong> from running</li>
</ul>



<h2 class="wp-block-heading" id="h-what-about-optimistic-locking">What about Optimistic locking?</h2>



<p class="wp-block-paragraph">Redis is able to use a <strong>check and set </strong>method to lock the Redis transaction.</p>



<p class="wp-block-paragraph">For that we will use the <strong>WATCH </strong>command.</p>



<p class="wp-block-paragraph">I invite you to check the  Redis site to see some use cases on how optimistic locking is working</p>



<h2 class="wp-block-heading" id="redis-scripting-and-transactions">Redis scripting </h2>



<p class="wp-block-paragraph">Another solution is to use Redis scripts which are also transactional.</p>



<p class="wp-block-paragraph">That means that you can do the same actions as with a Redis Transaction,and usually the script will be both simpler and faster.</p>



<p class="wp-block-paragraph">You can have more info about scripts by following this <a href="https://redis.io/commands/eval/">link</a></p>



<h2 class="wp-block-heading" id="h-conclusion">Conclusion</h2>



<p class="wp-block-paragraph">Now you know how to perform transactions in Redis, a useful feature to keep data consistency and in a very fast way <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p class="wp-block-paragraph">Feel free to check <a href="https://www.dbi-services.com/blog/author/nabilsaoual/">my other posts </a>and also keep an eye on <a href="https://www.dbi-services.com/blog/">dbi bloggers</a> for new tips and tricks.</p>
<p>L’article <a href="https://www.dbi-services.com/blog/redis-how-transactions-work-in-redis/">Redis: How transactions work in Redis</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/redis-how-transactions-work-in-redis/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MongoDB: Identify a field type</title>
		<link>https://www.dbi-services.com/blog/mongodb-identify-a-field-type/</link>
					<comments>https://www.dbi-services.com/blog/mongodb-identify-a-field-type/#respond</comments>
		
		<dc:creator><![CDATA[Middleware Team]]></dc:creator>
		<pubDate>Wed, 27 Sep 2023 07:56:22 +0000</pubDate>
				<category><![CDATA[NoSQL]]></category>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/?p=28229</guid>

					<description><![CDATA[<p>Introduction Whereas I wanted to perform a quick demo to show some MongoDB useful command to mass update some fields (Increment),I had a MongoDB error: “Cannot increment with a non-numeric argument” I guess the message is explicit: I can’t update this field as it is not a numeric field Identify the field type: As I [&#8230;]</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-identify-a-field-type/">MongoDB: Identify a field type</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="h-introduction">Introduction</h2>



<p class="wp-block-paragraph">Whereas I wanted to perform a quick demo to show some MongoDB useful command to mass</p>



<p class="wp-block-paragraph">update some fields (Increment),I had a MongoDB error: “Cannot increment with a non-numeric argument”</p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-64.png" alt="" class="wp-image-28232" style="width:1175px;height:41px" width="1175" height="41" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-64.png 602w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-64-300x10.png 300w" sizes="auto, (max-width: 1175px) 100vw, 1175px" /></figure>



<p class="wp-block-paragraph">I guess the message is explicit:</p>



<p class="wp-block-paragraph">I can’t update this field as it is not a numeric field</p>



<h2 class="wp-block-heading" id="h-identify-the-field-type">Identify the field type:</h2>



<p class="wp-block-paragraph">As I have created my document with basic commands without specifying each field type, the fields are set by default (<strong>undefined</strong> )</p>



<h2 class="wp-block-heading" id="h-how-to-know-the-type-of-your-field">How to know the type of your field?</h2>



<p class="wp-block-paragraph">For my example I have this list of players, their name, and also their <strong>number</strong> of goals.</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-66-1024x629.png" alt="" class="wp-image-28236" style="width:942px;height:579px" width="942" height="579" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-66-1024x629.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-66-300x184.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-66-768x471.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-66.png 1336w" sizes="auto, (max-width: 942px) 100vw, 942px" /></figure>



<p class="wp-block-paragraph">When I wanted to increment the &#8220;goals&#8221; field by 10 it displayed the famous issue.</p>



<p class="wp-block-paragraph">Let&#8217;s check the goals field type:</p>



<p class="wp-block-paragraph">For that we will use the below command:</p>



<pre class="wp-block-code"><code><strong>typeof </strong>db.collection.findOne().<strong>field_name</strong></code></pre>



<pre class="wp-block-code"><code>selecao_cracks&gt; typeof db.selecao_cracks.findOne().Lastname</code></pre>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-68-1024x326.png" alt="" class="wp-image-28241" style="width:946px;height:301px" width="946" height="301" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-68-1024x326.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-68-300x96.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-68-768x245.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-68.png 1344w" sizes="auto, (max-width: 946px) 100vw, 946px" /></figure>



<p class="wp-block-paragraph">Here we see that <strong>Lastname </strong>field is undefined</p>



<p class="wp-block-paragraph">If we take a look we see that Nickname field is a string type (I made some tests before) </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="159" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-69-1024x159.png" alt="" class="wp-image-28245" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-69-1024x159.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-69-300x47.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-69-768x119.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-69.png 1096w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading" id="h-the-type-operator">The $TYPE operator:</h2>



<p class="wp-block-paragraph">The <a href="https://www.mongodb.com/docs/manual/reference/operator/query/type/#mongodb-query-op.-type"><code>$type</code></a> operator accepts string aliases for the BSON types in addition to the numbers corresponding to the BSON types</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="748" height="903" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-67.png" alt="" class="wp-image-28240" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-67.png 748w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-67-249x300.png 249w" sizes="auto, (max-width: 748px) 100vw, 748px" /></figure>



<h2 class="wp-block-heading" id="h-update-the-type-of-the-field">Update the type of the field</h2>



<p class="wp-block-paragraph">Use the <strong>$set</strong> operator and the <strong>$toInt</strong> operator to update the field ( In fact in that case the <strong>$set</strong> operator will replace the field and its type, later we will see that we can use another operator name <strong>$convert </strong>)</p>



<pre class="wp-block-code"><code>selecao_cracks&gt; db.selecao_cracks.updateMany( {}, &#091;{ <strong>$set</strong> : { "goals":{<strong>$toInt</strong>:"$goals"}}} ]);</code></pre>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-70-1024x277.png" alt="" class="wp-image-28249" style="width:993px;height:269px" width="993" height="269" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-70-1024x277.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-70-300x81.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-70-768x208.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-70-1536x415.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-70.png 1621w" sizes="auto, (max-width: 993px) 100vw, 993px" /></figure>



<ul class="wp-block-list">
<li>Check if the field is updated</li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-71-1024x204.png" alt="" class="wp-image-28251" style="width:990px;height:197px" width="990" height="197" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-71-1024x204.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-71-300x60.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-71-768x153.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-71.png 1328w" sizes="auto, (max-width: 990px) 100vw, 990px" /></figure>



<h2 class="wp-block-heading" id="h-increment-the-field-to-check-if-the-command-is-now-valid">Increment the field to check if the command is now valid</h2>



<pre class="wp-block-code"><code>selecao_cracks&gt; db.selecao_cracks.updateMany( {}, { $inc : { goals : 10 } });</code></pre>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-72-1024x198.png" alt="" class="wp-image-28253" style="width:993px;height:192px" width="993" height="192" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-72-1024x198.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-72-300x58.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-72-768x148.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-72-1536x297.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-72.png 1642w" sizes="auto, (max-width: 993px) 100vw, 993px" /></figure>



<ul class="wp-block-list">
<li>Now let&#8217;s check if update is done </li>
</ul>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-73-1024x601.png" alt="" class="wp-image-28255" style="width:988px;height:580px" width="988" height="580" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-73-1024x601.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-73-300x176.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-73-768x450.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-73.png 1398w" sizes="auto, (max-width: 988px) 100vw, 988px" /></figure>



<p class="wp-block-paragraph">That&#8217;s it update worked and we don&#8217;t have the error related to the data type <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h2 class="wp-block-heading" id="h-the-other-operators">The other operators</h2>



<p class="wp-block-paragraph">We have also other operator to change our field type such as:</p>



<p class="wp-block-paragraph"><strong>$toString</strong></p>



<p class="wp-block-paragraph">As it&#8217;s name says it is to change the field to a string type</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-74-1024x276.png" alt="" class="wp-image-28285" style="width:989px;height:267px" width="989" height="267" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-74-1024x276.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-74-300x81.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-74-768x207.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-74-1536x414.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-74.png 1867w" sizes="auto, (max-width: 989px) 100vw, 989px" /></figure>



<p class="wp-block-paragraph"><strong>$toDate</strong></p>



<p class="wp-block-paragraph">this operator allows you to modify the field as a <strong>date </strong>type</p>



<p class="wp-block-paragraph">Example:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="699" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-75-1024x699.png" alt="" class="wp-image-28305" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-75-1024x699.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-75-300x205.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-75-768x524.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-75.png 1216w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>We check the data type:</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="242" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-77-1024x242.png" alt="" class="wp-image-28308" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-77-1024x242.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-77-300x71.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-77-768x182.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-77-1536x363.png 1536w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-77.png 1703w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>Update the field</li>
</ul>



<pre class="wp-block-code"><code>ballon_d_or_winner&gt; db.ballon_d_or_forgotten.updateOne( {"name":"Zico"}, &#091;{ $set : { "date":{$toDate:"$date"}}} ]);
</code></pre>



<ul class="wp-block-list">
<li>The output shows that it worked</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="231" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-79-1024x231.png" alt="" class="wp-image-28315" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-79-1024x231.png 1024w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-79-300x68.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-79-768x173.png 768w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-79.png 1414w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<ul class="wp-block-list">
<li>We see that the format is note an <strong>ISODate </strong>format</li>
</ul>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="880" height="864" src="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-78.png" alt="" class="wp-image-28314" srcset="https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-78.png 880w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-78-300x295.png 300w, https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2023/09/image-78-768x754.png 768w" sizes="auto, (max-width: 880px) 100vw, 880px" /></figure>



<p class="wp-block-paragraph"><strong>$Convert</strong></p>



<p class="wp-block-paragraph">For converting the data type of a field in MongoDB.</p>



<p class="wp-block-paragraph">More information related to <strong>$Convert </strong>on the <a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/">MongoDB site</a> </p>



<p class="wp-block-paragraph">This operator is very effective and can convert a field to any data type, or it can convert a field to null if the conversion is not possible.</p>



<p class="wp-block-paragraph"><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#mongodb-expression-exp.-convert"><code>$convert</code></a> has the following syntax:</p>



<pre class="wp-block-code"><code>{<br>$convert:<br>{<br>input: ,<br>to: ,<br>onError: , // Optional.<br>onNull: // Optional.<br>}<br>}</code></pre>



<p class="wp-block-paragraph">In addition to <a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#mongodb-expression-exp.-convert"><code>$convert</code></a>, MongoDB provides the following aggregation operators as shorthand when the default &#8220;onError&#8221; and &#8220;onNull&#8221; behavior is acceptable:</p>



<ul class="wp-block-list">
<li><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/#mongodb-expression-exp.-toBool"><code>$toBool</code></a></li>



<li><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/#mongodb-expression-exp.-toDate"><code>$toDate</code></a></li>



<li><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/#mongodb-expression-exp.-toDecimal"><code>$toDecimal</code></a></li>



<li><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/#mongodb-expression-exp.-toDouble"><code>$toDouble</code></a></li>



<li><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/#mongodb-expression-exp.-toInt"><code>$toInt</code></a></li>



<li><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/#mongodb-expression-exp.-toLong"><code>$toLong</code></a></li>



<li><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/#mongodb-expression-exp.-toObjectId"><code>$toObjectId</code></a></li>



<li><a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/#mongodb-expression-exp.-toString"><code>$toString</code></a></li>
</ul>



<h2 class="wp-block-heading" id="h-conclusion">Conclusion </h2>



<p class="wp-block-paragraph">Now you know how to update a field with the correct type especially when you need to performs tasks using integer values.</p>



<p class="wp-block-paragraph">I hope it helped, next time we will go deeper with these kind of operator especially combined with aggregations as it is a huge topic with many use cases.</p>



<p class="wp-block-paragraph">Don&#8217;t hesitate to check <a href="https://www.dbi-services.com/blog/author/nabilsaoual/page/5/">my other blogs</a> and share with dbi bloggers.</p>
<p>L’article <a href="https://www.dbi-services.com/blog/mongodb-identify-a-field-type/">MongoDB: Identify a field type</a> est apparu en premier sur <a href="https://www.dbi-services.com/blog">dbi Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbi-services.com/blog/mongodb-identify-a-field-type/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: www.dbi-services.com @ 2026-07-29 07:00:05 by W3 Total Cache
-->