url
stringlengths 36
137
| content
stringlengths 1.21k
7.75M
|
---|---|
https://www.mongodb.com/docs/manual/core/security-encryption-at-rest/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Encryption at Rest
<a class="headerlink leafygreen-ui-1kepx47" href="#encryption-at-rest" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="encryption-at-rest">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#encrypted-storage-engine" target="_self">
<span>
Encrypted Storage Engine
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#application-level-encryption" target="_self">
<span>
Application Level Encryption
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Encryption at rest, when used in conjunction with transport encryption
and security policies that protect relevant accounts, passwords, and
encryption keys, can help ensure compliance with security and privacy
standards, including HIPAA, PCI-DSS, and FERPA.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-encrypted-storage-engine">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Encrypted Storage Engine
<a class="headerlink leafygreen-ui-1kepx47" href="#encrypted-storage-engine" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="encrypted-storage-engine">
</div>
</a>
</h2>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Enterprise Feature
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Available in MongoDB Enterprise only.
</p>
</div>
</div>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Available for the WiredTiger Storage Engine only.
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB Enterprise 3.2 introduces a native encryption option for the
WiredTiger storage engine. This feature allows MongoDB to encrypt data
files such that only parties with the decryption key can decode and
read the data.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Encryption Process
<a class="headerlink leafygreen-ui-1kepx47" href="#encryption-process" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="encryption-process">
</div>
</a>
</h3>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
MongoDB Enterprise on Windows no longer supports
<code class="leafygreen-ui-1l06pbn">
AES256-GCM
</code>
as a
block cipher for encryption at rest. This usage is only supported on Linux.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If encryption is enabled, the default encryption mode that MongoDB
Enterprise uses is the
<code class="leafygreen-ui-1l06pbn">
AES256-CBC
</code>
(or 256-bit Advanced Encryption
Standard in Cipher Block Chaining mode) via OpenSSL. AES-256 uses a
symmetric key; i.e. the same key to encrypt and decrypt text. MongoDB
Enterprise for Linux also supports authenticated encryption
<code class="leafygreen-ui-1l06pbn">
AES256-GCM
</code>
(or 256-bit Advanced Encryption Standard in
Galois/Counter Mode).
</p>
<p class="leafygreen-ui-1kp3ins">
The Encrypted Storage Engine uses the certified cryptography provider
of the underlying operating system to perform cryptographic operations.
For example, a MongoDB installation on a Linux operating system
uses the OpenSSL
<code class="leafygreen-ui-1l06pbn">
libcrypto
</code>
FIPS-140 module.
</p>
<p class="leafygreen-ui-1kp3ins">
To run MongoDB in a FIPS-compliant mode:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Configure the operating system to run in FIPS-enforcing mode.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Configure MongoDB to enable the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.FIPSMode">
<code class="leafygreen-ui-1l06pbn">
net.tls.FIPSMode
</code>
</a>
setting.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Restart the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
or
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Check the server log file to confirm that FIPS mode is enabled. If FIPS mode is enabled, the message
<code class="leafygreen-ui-1l06pbn">
FIPS 140-2 mode activated
</code>
appears in the log file.
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-fips/#std-label-configure-mdb-for-fips">
Configure MongoDB for FIPS
<!-- -->
.
</a>
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
AES256-GCM and Filesystem Backups
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
For
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-encrypted-storage-engine" target="_self">
<span>
encrypted storage engines
</span>
</a>
that
use
<code class="leafygreen-ui-1l06pbn">
AES256-GCM
</code>
encryption mode,
<code class="leafygreen-ui-1l06pbn">
AES256-GCM
</code>
requires that every
process use a unique counter block value with the key.
</p>
<p class="leafygreen-ui-1kp3ins">
For
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-encrypted-storage-engine" target="_self">
<span>
encrypted storage engine
</span>
</a>
configured with
<code class="leafygreen-ui-1l06pbn">
AES256-GCM
</code>
cipher:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<dl>
<dt>
Restoring from Hot Backup
</dt>
<dd class="css-1ufxuu7">
Starting in 4.2, if you restore from files taken via "hot"
backup (i.e. the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
is running), MongoDB
can detect "dirty" keys on startup and automatically rollover
the database key to avoid IV (Initialization Vector) reuse.
</dd>
</dl>
</li>
<li class="leafygreen-ui-d7p7b6">
<dl>
<dt>
Restoring from Cold Backup
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
However, if you restore from files taken via "cold" backup
(i.e. the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
is not running), MongoDB
cannot detect "dirty" keys on startup, and reuse of IV voids
confidentiality and integrity guarantees.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in 4.2, to avoid the reuse of the keys after
restoring from a cold filesystem snapshot, MongoDB adds a new
command-line option
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--eseDatabaseKeyRollover">
<code class="leafygreen-ui-1l06pbn">
--eseDatabaseKeyRollover
</code>
</a>
. When started with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--eseDatabaseKeyRollover">
<code class="leafygreen-ui-1l06pbn">
--eseDatabaseKeyRollover
</code>
</a>
option, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance rolls over the database keys configured with
<code class="leafygreen-ui-1l06pbn">
AES256-GCM
</code>
cipher and exits.
</p>
</dd>
</dl>
</li>
</ul>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The data encryption process includes:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Generating a master key.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Generating keys for each database.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Encrypting data with the database keys.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Encrypting the database keys with the master key.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The encryption occurs transparently in the storage layer; i.e. all data
files are fully encrypted from a filesystem perspective, and data only
exists in an unencrypted state in memory and during transmission.
</p>
<p class="leafygreen-ui-1kp3ins">
To encrypt all of MongoDB's network traffic, you can use TLS/SSL
(Transport Layer Security/Secure Sockets Layer). See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/">
Configure
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
and
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
for TLS/SSL
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl-clients/">
TLS/SSL Configuration for Clients
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Key Management
<a class="headerlink leafygreen-ui-1kepx47" href="#key-management" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="key-management">
</div>
</a>
</h3>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Secure management of the encryption keys is critical.
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The database keys are internal to the server and are only paged to disk
in an encrypted format. MongoDB never pages the master key to disk
under any circumstances.
</p>
<p class="leafygreen-ui-1kp3ins">
Only the master key is external to the server (i.e. kept separate from
the data and the database keys), and requires external management. To
manage the master key, MongoDB's encrypted storage engine supports two
key management options:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Integration with a third party key management appliance via the Key
Management Interoperability Protocol (KMIP).
<strong>
Recommended
</strong>
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
For an integration with a third-party key management appliance using
the
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
, you should allow the following KMIP operations:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Create (
<code class="leafygreen-ui-1l06pbn">
operation_create
</code>
)
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Get (
<code class="leafygreen-ui-1l06pbn">
operation_get
</code>
)
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Activate (
<code class="leafygreen-ui-1l06pbn">
operation_activate
</code>
)
</p>
</li>
</ul>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Local key management via a keyfile.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To configure MongoDB for encryption and use one of the two key
management options, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-encryption/">
Configure Encryption
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Encryption and Replication
<a class="headerlink leafygreen-ui-1kepx47" href="#encryption-and-replication" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="encryption-and-replication">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Encryption is not a part of replication:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Master keys and database keys are not replicated, and
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Data is not natively encrypted over the wire.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Although you could reuse the same key for the nodes, MongoDB recommends
the use of individual keys for each node as well as the use of
transport encryption.
</p>
<p class="leafygreen-ui-1kp3ins">
For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/rotate-encryption-key/#std-label-rotate-encryption-keys">
Rotate Encryption Keys
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-security-encryption-at-rest-audit-log">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Audit Log
<a class="headerlink leafygreen-ui-1kepx47" href="#audit-log" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="audit-log">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Available in MongoDB Enterprise only.
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Use KMIP Server to Manage Keys for Encrypting the MongoDB Audit Log
<a class="headerlink leafygreen-ui-1kepx47" href="#use-kmip-server-to-manage-keys-for-encrypting-the-mongodb-audit-log" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-kmip-server-to-manage-keys-for-encrypting-the-mongodb-audit-log">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0 Enterprise, you can securely manage the keys for
encrypting the MongoDB audit log using an external Key Management
Interoperability Protocol (KMIP) server.
</p>
<p class="leafygreen-ui-1kp3ins">
KMIP simplifies the management of cryptographic keys and eliminates the
use of non-standard key management processes.
</p>
<p class="leafygreen-ui-1kp3ins">
The default KMIP protocol version is 1.2. You can configure MongoDB to
use KMIP version 1.0 or 1.1 in the MongoDB server
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
configuration
file
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To use a KMIP server with audit log encryption, configure these settings
and parameters:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-auditLog.auditEncryptionKeyIdentifier">
<code class="leafygreen-ui-1l06pbn">
auditLog.auditEncryptionKeyIdentifier
</code>
</a>
setting
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-auditLog.compressionMode">
<code class="leafygreen-ui-1l06pbn">
auditLog.compressionMode
</code>
</a>
setting
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.auditEncryptionHeaderMetadataFile">
<code class="leafygreen-ui-1l06pbn">
auditEncryptionHeaderMetadataFile
</code>
</a>
parameter
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.auditEncryptKeyWithKMIPGet">
<code class="leafygreen-ui-1l06pbn">
auditEncryptKeyWithKMIPGet
</code>
</a>
parameter
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For testing audit log encryption, you can also use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-auditLog.localAuditKeyFile">
<code class="leafygreen-ui-1l06pbn">
auditLog.localAuditKeyFile
</code>
</a>
setting.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, if you need to downgrade to an earlier MongoDB
version, you must first disable audit log encryption by removing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-auditLog.auditEncryptionKeyIdentifier">
<code class="leafygreen-ui-1l06pbn">
auditLog.auditEncryptionKeyIdentifier
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-auditLog.localAuditKeyFile">
<code class="leafygreen-ui-1l06pbn">
auditLog.localAuditKeyFile
</code>
</a>
. Existing encrypted audit logs
remain encrypted, and you can keep any procedures you have developed for
storage and processing of encrypted logs.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
For audit log encryption, the audit log destination must be a
file.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-syslog">
syslog
</a>
cannot be used as the destination.
</p>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Unencrypted Audit Log and Process Log
<a class="headerlink leafygreen-ui-1kepx47" href="#unencrypted-audit-log-and-process-log" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="unencrypted-audit-log-and-process-log">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
This section applies if you are not using an external Key Management
Interoperability Protocol (KMIP) server to manage keys for encrypting
the audit log as shown in the previous section.
</p>
<p class="leafygreen-ui-1kp3ins">
The audit log file is not encrypted as a part of MongoDB's encrypted
storage engine. A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/monitoring/#std-label-monitoring-standard-loggging">
logging
</a>
may output potentially sensitive
information to log files as a part of normal operations, depending on
the configured
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-configure-verbosity">
log verbosity
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.redactClientLogData">
<code class="leafygreen-ui-1l06pbn">
security.redactClientLogData
</code>
</a>
setting to prevent
potentially sensitive information from entering the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
process
log. Setting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.redactClientLogData">
<code class="leafygreen-ui-1l06pbn">
redactClientLogData
</code>
</a>
reduces detail in
the log and may complicate log diagnostics.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/monitoring/#std-label-monitoring-log-redaction">
log redaction
</a>
manual entry for
more information.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-app-level-encryption">
</span>
</section>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Application Level Encryption
<a class="headerlink leafygreen-ui-1kepx47" href="#application-level-encryption" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="application-level-encryption">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, you can use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe">
Queryable Encryption
</a>
to
enable end-to-end encryption. For details on getting started, see
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/quick-start/#std-label-qe-quick-start">
Quick Start
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For a list of MongoDB's certified partners,
refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/partners/list" target="_self">
<span>
Partners List
</span>
</a>
.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/KeyVault.getKeys/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
KeyVault.getKeys()
<a class="headerlink leafygreen-ui-1kepx47" href="#keyvault.getkeys--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="keyvault.getkeys--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
KeyVault.getKeys()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-KeyVault.getKeys" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-KeyVault.getKeys">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.getKeys" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getKeys()
</code>
</span>
</a>
returns all data encryption keys stored
in the key vault associated to the database connection.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.getKeys" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getKeys()
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"keyVault = db.getMongo().getKeyVault()\n\nkeyVault.getKeys()"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">keyVault = db.getMongo().getKeyVault()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVault.getKeys()</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<table class="css-11h39yh e1nex8bq0">
<colgroup>
<col class="field-name"/>
<col class="field-body"/>
</colgroup>
<tbody>
<tr class="css-x8snli">
<th>
Returns
<!-- -->
:
</th>
<td>
Returns all data encryption keys associated to the key vault.
<p class="leafygreen-ui-1kp3ins">
Returns nothing if the key vault is empty.
</p>
</td>
</tr>
</tbody>
</table>
</dd>
</dl>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Requires Configuring Client-Side Field Level Encryption on Database Connection
<a class="headerlink leafygreen-ui-1kepx47" href="#requires-configuring-client-side-field-level-encryption-on-database-connection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="requires-configuring-client-side-field-level-encryption-on-database-connection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
client-side field level encryption methods
require a database connection with client-side field level encryption
enabled. If the current database connection was not initiated with
client-side field level encryption enabled, either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
<code class="leafygreen-ui-1l06pbn">
Mongo()
</code>
</a>
constructor from the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to establish a connection with the required client-side field
level encryption options. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
<code class="leafygreen-ui-1l06pbn">
Mongo()
</code>
</a>
method supports the
following Key Management Service (KMS) providers for Customer
Master Key (CMK) management:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-aws">
Amazon Web Services KMS
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-azure">
Azure Key Vault
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-gcp">
Google Cloud Platform KMS
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-local">
Locally Managed Key
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<em>
or
</em>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/options/#std-label-mongosh-client-side-field-level-encryption-options" target="_self">
<span>
command line options
</span>
</a>
to establish a
connection with the required options. The command line options only
support the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-aws">
Amazon Web Services KMS
</a>
provider for CMK management.
</p>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following example uses a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-local">
locally managed KMS
</a>
for the client-side field level
encryption configuration.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start the mongosh client.","name":"Start mongosh"},{"@type":"HowToStep","text":"To configure client-side field level encryption for a locally\nmanaged key, generate a base64-encoded 96-byte string with no line\nbreaks.","name":"Generate Your Key"},{"@type":"HowToStep","text":"Create the client-side field level encryption options using the\ngenerated local key string:","name":"Create the Client-Side Field Level Encryption Options"},{"@type":"HowToStep","text":"Use the Mongo() constructor with the client-side field level\nencryption options configured to create a database connection. Replace\nthe mongodb://myMongo.example.net URI with the connection\nstring URI of the target cluster.","name":"Create Your Encrypted Client"}],"name":"Example","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Start mongosh
<a class="headerlink leafygreen-ui-1kepx47" href="#start-mongosh" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="start-mongosh">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Start the
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
client.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongosh --nodb","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh --nodb</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Generate Your Key
<a class="headerlink leafygreen-ui-1kepx47" href="#generate-your-key" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="generate-your-key">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To configure client-side field level encryption for a locally
managed key, generate a base64-encoded 96-byte string with no line
breaks.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const TEST_LOCAL_KEY = require(\"crypto\").randomBytes(96).toString(\"base64\")","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> <span class="lg-highlight-variable lg-highlight-constant">TEST_LOCAL_KEY</span> <!-- -->= <span class="lg-highlight-built_in">require</span>(<span class="lg-highlight-string">"crypto"</span>).<span class="lg-highlight-title lg-highlight-function">randomBytes</span>(<span class="lg-highlight-number">96</span>).<span class="lg-highlight-title lg-highlight-function">toString</span>(<span class="lg-highlight-string">"base64"</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create the Client-Side Field Level Encryption Options
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-client-side-field-level-encryption-options" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-the-client-side-field-level-encryption-options">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create the client-side field level encryption options using the
generated local key string:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" var autoEncryptionOpts = {\n \"keyVaultNamespace\" : \"encryption.__dataKeys\",\n \"kmsProviders\" : {\n \"local\" : {\n \"key\" : BinData(0, TEST_LOCAL_KEY)\n }\n }\n }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> autoEncryptionOpts <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"keyVaultNamespace"</span> <!-- -->: <span class="lg-highlight-string">"encryption.__dataKeys"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"kmsProviders"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"local"</span> <!-- -->: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-variable lg-highlight-constant">TEST_LOCAL_KEY</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create Your Encrypted Client
<a class="headerlink leafygreen-ui-1kepx47" href="#create-your-encrypted-client" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-your-encrypted-client">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
<code class="leafygreen-ui-1l06pbn">
Mongo()
</code>
</a>
constructor with the client-side field level
encryption options configured to create a database connection. Replace
the
<code class="leafygreen-ui-1l06pbn">
mongodb://myMongo.example.net
</code>
URI with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string/#std-label-mongodb-uri">
connection
string URI
</a>
of the target cluster.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"encryptedClient = Mongo(\n \"mongodb://myMongo.example.net:27017/?replSetName=myMongo\",\n autoEncryptionOpts\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">encryptedClient <!-- -->= <span class="lg-highlight-title lg-highlight-class">Mongo</span>(</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"mongodb://myMongo.example.net:27017/?replSetName=myMongo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->autoEncryptionOpts</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Retrieve the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/getKeyVault/#mongodb-method-getKeyVault">
<code class="leafygreen-ui-1l06pbn">
KeyVault
</code>
</a>
object and use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.getKeys" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
KeyVault.getKeys()
</code>
</span>
</a>
method to retrieve all data encryption keys
in the key vault:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"keyVault.getKeys()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">keyVault.<span class="lg-highlight-title lg-highlight-function">getKeys</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.getKeys" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getKeys()
</code>
</span>
</a>
returns all data encryption keys in the
key vault, with output similar to the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : UUID(\"b4b41b33-5c97-412e-a02b-743498346079\"),\n \"keyMaterial\" : BinData(0,\"PXRsLOAYxhzTS/mFQAI8486da7BwZgqA91UI7NKz/T/AjB0uJZxTvhvmQQsKbCJYsWVS/cp5Rqy/FUX2zZwxJOJmI3rosPhzV0OI5y1cuXhAlLWlj03CnTcOSRzE/YIrsCjMB0/NyiZ7MRWUYzLAEQnE30d947XCiiHIb8a0kt2SD0so8vZvSuP2n0Vtz4NYqnzF0CkhZSWFa2e2yA==\"),\n \"creationDate\" : ISODate(\"2021-03-15T12:21:13.123Z\"),\n \"updateDate\" : ISODate(\"2021-03-15T12:21:13.123Z\"),\n \"status\" : 0, \"version\" : NumberLong(0),\n \"masterKey\" : {\n \"provider\" : \"local\"\n },\n \"keyAltNames\" : [\n \"alpha\"\n ]\n}\n{\n \"_id\" : UUID(\"f1add015-c7ab-49a2-a071-50b0ca0a8fbc\"),\n \"keyMaterial\" : BinData(0,\"E+0jZKzA4YuE1lGmSVIy2mivqH4JxFo0yFATdxYX/s0YtMFsgVXyu7Bbn4IQ2gn7F/9JAPJFOxdQc5lN3AR+oX33ewVZsd63f3DN1zzcukqdR2Y+EeO7ekRxyRjdzMaNNrBNIv9Gn5LEJgWPSYkG8VczF7cNZnc1YmnR0tuDPNYfm0J7dCZuZUNWW3FCGRcdFx6AlXiCtXKNR97hJ216pQ==\"),\n \"creationDate\" : ISODate(\"2021-03-16T18:22:43.733Z\"),\n \"updateDate\" : ISODate(\"2021-03-16T18:22:43.733Z\"),\n \"status\" : 0, \"version\" : NumberLong(0),\n \"masterKey\" : {\n \"provider\" : \"local\"\n },\n \"keyAltNames\" : [\n \"baker\"\n ]\n}","programmingLanguage":"JSON"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"_id"</span> <span class="lg-highlight-punctuation">:</span> UUID(<span class="lg-highlight-string">"b4b41b33-5c97-412e-a02b-743498346079"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"keyMaterial"</span> <span class="lg-highlight-punctuation">:</span> BinData(<span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span><span class="lg-highlight-string">"PXRsLOAYxhzTS/mFQAI8486da7BwZgqA91UI7NKz/T/AjB0uJZxTvhvmQQsKbCJYsWVS/cp5Rqy/FUX2zZwxJOJmI3rosPhzV0OI5y1cuXhAlLWlj03CnTcOSRzE/YIrsCjMB0/NyiZ7MRWUYzLAEQnE30d947XCiiHIb8a0kt2SD0so8vZvSuP2n0Vtz4NYqnzF0CkhZSWFa2e2yA=="</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"creationDate"</span> <span class="lg-highlight-punctuation">:</span> ISODate(<span class="lg-highlight-string">"2021-03-15T12:21:13.123Z"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"updateDate"</span> <span class="lg-highlight-punctuation">:</span> ISODate(<span class="lg-highlight-string">"2021-03-15T12:21:13.123Z"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"status"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"version"</span> <span class="lg-highlight-punctuation">:</span> NumberLong(<span class="lg-highlight-number">0</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"masterKey"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"provider"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"keyAltNames"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"alpha"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"_id"</span> <span class="lg-highlight-punctuation">:</span> UUID(<span class="lg-highlight-string">"f1add015-c7ab-49a2-a071-50b0ca0a8fbc"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"keyMaterial"</span> <span class="lg-highlight-punctuation">:</span> BinData(<span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span><span class="lg-highlight-string">"E+0jZKzA4YuE1lGmSVIy2mivqH4JxFo0yFATdxYX/s0YtMFsgVXyu7Bbn4IQ2gn7F/9JAPJFOxdQc5lN3AR+oX33ewVZsd63f3DN1zzcukqdR2Y+EeO7ekRxyRjdzMaNNrBNIv9Gn5LEJgWPSYkG8VczF7cNZnc1YmnR0tuDPNYfm0J7dCZuZUNWW3FCGRcdFx6AlXiCtXKNR97hJ216pQ=="</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"creationDate"</span> <span class="lg-highlight-punctuation">:</span> ISODate(<span class="lg-highlight-string">"2021-03-16T18:22:43.733Z"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"updateDate"</span> <span class="lg-highlight-punctuation">:</span> ISODate(<span class="lg-highlight-string">"2021-03-16T18:22:43.733Z"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"status"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"version"</span> <span class="lg-highlight-punctuation">:</span> NumberLong(<span class="lg-highlight-number">0</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"masterKey"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"provider"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"local"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"keyAltNames"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"baker"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/cursor.forEach/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
cursor.forEach()
<a class="headerlink leafygreen-ui-1kepx47" href="#cursor.foreach--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="cursor.foreach--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#method-fields" target="_self">
<span>
Method Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
cursor.forEach(function)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.forEach" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-cursor.forEach">
</div>
</a>
</dt>
<dd>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for a language-specific driver, such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Iterates the cursor to apply a JavaScript
<code class="leafygreen-ui-1l06pbn">
function
</code>
to each
document from the cursor.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The method has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find().forEach( <function> )","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">forEach</span>( <<span class="lg-highlight-keyword lg-highlight-function">function</span>> <!-- -->)</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Method Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#method-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="method-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The method accepts the following field:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
function
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
JavaScript code
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Function to apply to each document returned from the cursor. The
function signature includes one field that stores the current
document that is read from the cursor.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Create the
<code class="leafygreen-ui-1l06pbn">
users
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.users.insertMany( [\n { name: \"John\" },\n { name: \"Jane\" }\n] )"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.users.insertMany( [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { name: "John" },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { name: "Jane" }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example uses
<code class="leafygreen-ui-1l06pbn">
forEach()
</code>
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
find()
</code>
</a>
method to print the user names that are
read from the
<code class="leafygreen-ui-1l06pbn">
users
</code>
collection.
<code class="leafygreen-ui-1l06pbn">
myDoc
</code>
stores the current
document.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.users.find().forEach( function( myDoc ) {\n print( \"User name: \" + myDoc.name )\n} )"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.users.find().forEach( function( myDoc ) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> print( "User name: " + myDoc.name )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Example output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"User name: John\nUser name: Jane"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">User name: John</td></tr><tr class=""><td class="leafygreen-ui-7razhx">User name: Jane</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Starting in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
2.1.0, you can also use
<code class="leafygreen-ui-1l06pbn">
for-of
</code>
loops. The following example returns the same results as the previous
example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"for ( const myDoc of db.users.find() ) {\n print( \"User name: \" + myDoc.name )\n}"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">for ( const myDoc of db.users.find() ) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> print( "User name: " + myDoc.name )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For a method that has similar functionality, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.map/#mongodb-method-cursor.map">
<code class="leafygreen-ui-1l06pbn">
cursor.map()
</code>
.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/rotate-encryption-key/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Rotate Encryption Keys
<a class="headerlink leafygreen-ui-1kepx47" href="#rotate-encryption-keys" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rotate-encryption-keys">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#rotate-a-replica-set-member" target="_self">
<span>
Rotate a Replica Set Member
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#kmip-master-key-rotation" target="_self">
<span>
KMIP Master Key Rotation
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Most regulatory requirements mandate that a managed key used to decrypt
sensitive data must be rotated out and replaced with a new key once a
year.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Disambiguation
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To roll over database keys configured with AES256-GCM cipher after a
filesystem restore, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--eseDatabaseKeyRollover">
<code class="leafygreen-ui-1l06pbn">
--eseDatabaseKeyRollover
</code>
</a>
instead.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB provides two options for key rotation. You can rotate out the
binary with a new instance that uses a new key. Or, if you are using a
KMIP server for key management, you can rotate the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-Customer-Master-Key">
Customer Master Key
<!-- -->
.
</a>
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Rotate a Replica Set Member
<a class="headerlink leafygreen-ui-1kepx47" href="#rotate-a-replica-set-member" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rotate-a-replica-set-member">
</div>
</a>
</h2>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To prevent changing the write quorum, never rotate more than one
replica set member at a time.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For a replica set, to rotate out a member:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Start a new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance, configured to use a new key.
Include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--replSet">
<code class="leafygreen-ui-1l06pbn">
--replSet
</code>
</a>
option with the name of the replica set as
well as any other options specific to your configuration, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--dbpath">
<code class="leafygreen-ui-1l06pbn">
--dbpath
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip">
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --replSet myReplSet --enableEncryption \\\n--kmipServerName <kmip> \\\n--kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --replSet myReplSet --enableEncryption \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--kmipServerName <KMIP Server HostName> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to the replica set's primary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Add the instance to the replica set:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"rs.add( { host: <host:port> } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">rs.<span class="lg-highlight-title lg-highlight-function">add</span>( <!-- -->{ <span class="lg-highlight-attr">host</span>: <<span class="lg-highlight-attr">host</span>:<!-- -->port<!-- -->> <!-- -->} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Before MongoDB 5.0, a newly added secondary still counts as a voting
member even though it can neither serve reads nor become primary until
its data is consistent. If you are running a MongoDB version earlier
than 5.0 and add a secondary with its
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes">
<code class="leafygreen-ui-1l06pbn">
votes
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.priority">
<code class="leafygreen-ui-1l06pbn">
priority
</code>
</a>
settings greater than zero, this can
lead to a case where a majority of the voting members are
online but no primary can be elected. To avoid such situations,
consider adding the new secondary initially with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.priority">
<code class="leafygreen-ui-1l06pbn">
priority :0
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes">
<code class="leafygreen-ui-1l06pbn">
votes :0
</code>
</a>
. Then, run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.status/#mongodb-method-rs.status">
<code class="leafygreen-ui-1l06pbn">
rs.status()
</code>
</a>
to ensure the
member has transitioned into
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
state. Finally, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.reconfig/#mongodb-method-rs.reconfig">
<code class="leafygreen-ui-1l06pbn">
rs.reconfig()
</code>
</a>
to update its priority and votes.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
During the initial sync process, the re-encryption of the data with
an entirely new set of database keys as well as a new system key
occurs.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Remove the old node from the replica set and delete all its data.
For instructions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/remove-replica-set-member/">
Remove Members from a Self-Managed Replica Set
</a>
</p>
</li>
</ol>
<span class="leafygreen-ui-1qnjd6d" id="std-label-kmip-master-key-rotation">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
KMIP Master Key Rotation
<a class="headerlink leafygreen-ui-1kepx47" href="#kmip-master-key-rotation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="kmip-master-key-rotation">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If you are using a KMIP server for key management, you can rotate
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-Customer-Master-Key">
Customer Master Key
</a>
, the only externally managed key. With the new
master key, the internal keystore will be re-encrypted but the
database keys will be otherwise left unchanged. This obviates the need
to re-encrypt the entire data set.
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Rotate the master key for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-members/#std-label-replica-set-secondary-members">
secondary
</a>
members of the replica set one at a
time.
</p>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Restart the secondary, including the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipRotateMasterKey">
<code class="leafygreen-ui-1l06pbn">
--kmipRotateMasterKey
</code>
</a>
option. Include any other
options specific to your configuration, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip">
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
</a>
. If
the member already includes the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipKeyIdentifier">
<code class="leafygreen-ui-1l06pbn">
--kmipKeyIdentifier
</code>
</a>
option, either update the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipKeyIdentifier">
<code class="leafygreen-ui-1l06pbn">
--kmipKeyIdentifier
</code>
</a>
option
with the new key to use or omit to request a new key from the
KMIP server:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --enableEncryption --kmipRotateMasterKey \\\n --kmipServerName <kmip> \\\n --kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --enableEncryption --kmipRotateMasterKey \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> --kmipServerName <KMIP Server HostName> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> --kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If using a configuration file, include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.kmip.rotateMasterKey">
<code class="leafygreen-ui-1l06pbn">
security.kmip.rotateMasterKey
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Upon successful completion of the master key rotation and
re-encryption of the database keystore, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
will exit.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Restart the secondary without the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipRotateMasterKey">
<code class="leafygreen-ui-1l06pbn">
--kmipRotateMasterKey
</code>
</a>
parameter. Include any other options specific to your
configuration, such as
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --enableEncryption --kmipServerName <kmip> \\\n --kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --enableEncryption --kmipServerName <KMIP Server HostName> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> --kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If using a configuration file, remove the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.kmip.rotateMasterKey">
<code class="leafygreen-ui-1l06pbn">
security.kmip.rotateMasterKey
</code>
</a>
setting.
</p>
</li>
</ol>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Step down the replica set primary.
</p>
<p class="leafygreen-ui-1kp3ins">
Connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to the primary and use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.stepDown/#mongodb-method-rs.stepDown">
<code class="leafygreen-ui-1l06pbn">
rs.stepDown()
</code>
</a>
to step down the primary and force an
election of a new primary:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"rs.stepDown()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">rs.<span class="lg-highlight-title lg-highlight-function">stepDown</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.status/#mongodb-method-rs.status">
<code class="leafygreen-ui-1l06pbn">
rs.status()
</code>
</a>
shows that the primary has stepped down and another member
has assumed
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
state, rotate the master key for the stepped down member:
</p>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Restart the stepped-down member, including the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipRotateMasterKey">
<code class="leafygreen-ui-1l06pbn">
--kmipRotateMasterKey
</code>
</a>
option. Include any other
options specific to your configuration, such as
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
. If the member already
includes the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipKeyIdentifier">
<code class="leafygreen-ui-1l06pbn">
--kmipKeyIdentifier
</code>
</a>
option, either update
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipKeyIdentifier">
<code class="leafygreen-ui-1l06pbn">
--kmipKeyIdentifier
</code>
</a>
option with the new key to use
or omit.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --enableEncryption --kmipRotateMasterKey \\\n --kmipServerName <kmip> \\\n --kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --enableEncryption --kmipRotateMasterKey \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> --kmipServerName <KMIP Server HostName> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> --kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If using a configuration file, include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.kmip.rotateMasterKey">
<code class="leafygreen-ui-1l06pbn">
security.kmip.rotateMasterKey
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Upon successful completion of the master key rotation and
re-encryption of the database keystore, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
will exit.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Restart the stepped-down member without the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipRotateMasterKey">
<code class="leafygreen-ui-1l06pbn">
--kmipRotateMasterKey
</code>
</a>
option. Include any other options
specific to your configuration, such as
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --enableEncryption --kmipServerName <kmip> \\\n --kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --enableEncryption --kmipServerName <KMIP Server HostName> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> --kmipServerCAFile ca.pem --kmipClientCertificateFile client.pem</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If using a configuration file, remove the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.kmip.rotateMasterKey">
<code class="leafygreen-ui-1l06pbn">
security.kmip.rotateMasterKey
</code>
</a>
setting.
</p>
</li>
</ol>
</li>
</ol>
</section>
</section>
|
https://www.mongodb.com/docs/manual/release-notes/6.0-downgrade-standalone/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Downgrade
<!-- -->
6.0
<!-- -->
Standalone to
<!-- -->
5.0
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-newversion-standalone-to-oldversion" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="downgrade-newversion-standalone-to-oldversion">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#downgrade-path" target="_self">
<span>
Downgrade Path
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#access-control" target="_self">
<span>
Access Control
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#prerequisites" target="_self">
<span>
Prerequisites
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#downgrade-procedure" target="_self">
<span>
Downgrade Procedure
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Before you attempt a downgrade, familiarize yourself with the content
in this page.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Downgrade Path
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-path" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="downgrade-path">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If you need to downgrade from
<!-- -->
6.0
<!-- -->
, downgrade to the latest
patch release of
<!-- -->
5.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB only supports single-version downgrades. You cannot downgrade to a
release that is multiple versions behind your current release.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, you may downgrade a
<!-- -->
6.0-series
<!-- -->
to a
<!-- -->
5.0-series
<!-- -->
deployment.
However, further downgrading that
<!-- -->
5.0-series
<!-- -->
deployment to a
<!-- -->
4.4-series
<!-- -->
deployment is not supported.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Access Control
<a class="headerlink leafygreen-ui-1kepx47" href="#access-control" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="access-control">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If your deployment has access control enabled, your downgrade user
privileges must include privileges to list and manage indexes across
databases. A user with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-root">
<code class="leafygreen-ui-1l06pbn">
root
</code>
</a>
role has the required
privileges.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Prerequisites
<a class="headerlink leafygreen-ui-1kepx47" href="#prerequisites" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="prerequisites">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Before you begin the downgrade procedure, you must complete the following
prerequisite steps.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
1. Create Backup
<a class="headerlink leafygreen-ui-1kepx47" href="#1.-create-backup" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="1.-create-backup">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional but Recommended.
</em>
Create a backup of your database.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn how to create a backup, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/backups/#std-label-backup-methods">
Backup Methods for a Self-Managed Deployment
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
2. Remove Backward-Incompatible Features
<a class="headerlink leafygreen-ui-1kepx47" href="#2.-remove-backward-incompatible-features" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="2.-remove-backward-incompatible-features">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To downgrade from
<!-- -->
6.0
<!-- -->
to
<!-- -->
5.0
<!-- -->
, you must remove
<!-- -->
6.0
<!-- -->
features that are incompatible with
<!-- -->
5.0
<!-- -->
. For a
list of incompatible features and how to remove them, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0-compatibility/#std-label-6.0-downgrade-considerations">
Downgrade Considerations
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
3. Downgrade Feature Compatibility Version (fCV)
<a class="headerlink leafygreen-ui-1kepx47" href="#3.-downgrade-feature-compatibility-version--fcv-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="3.-downgrade-feature-compatibility-version--fcv-">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To downgrade the
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
of your standalone
instance:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to connect to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance
<!-- -->
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Downgrade the
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
to
<code class="leafygreen-ui-1l06pbn">
"5.0"
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { setFeatureCompatibilityVersion: \"5.0\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">setFeatureCompatibilityVersion</span>: <span class="lg-highlight-string">"5.0"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
command performs writes
to an internal system collection and is idempotent. If the command does
not complete successfully, retry the command on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance
<!-- -->
.
</p>
</li>
</ol>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Downgrade Procedure
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-procedure" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="downgrade-procedure">
</div>
</a>
</h2>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Before proceeding with the downgrade procedure, ensure that the
prerequisites have been completed.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Using either a package manager or a manual download, get the\nlatest patch release in the 5.0 series. If using a\npackage manager, add a new repository for the 5.0\nbinaries, then perform the actual downgrade process.","name":"Download the latest 5.0 binaries."},{"@type":"HowToStep","text":"Ensure that the 5.0 binaries are in your System PATH. To\nconfirm your binary version, run the following command:The command output should indicate a 5.0-series release.","name":"Replace the 6.0 binaries with the downloaded 5.0 binaries."},{"@type":"HowToStep","text":"To shut down the mongod process, use\nmongosh to connect to the deployment and run the\nfollowing command:","name":"Shut down the mongod instance."},{"@type":"HowToStep","text":"Disable any configurable 6.0 features by updating the\nmongod instance's configuration file before\nrestarting.To see the list of configurable 6.0 features, review the\n6.0 Release Notes.","name":"Update configuration files."},{"@type":"HowToStep","text":"To start a mongod process, run the following command:To learn more about starting a mongod process, see\nStart mongod Processes.","name":"Restart with the latest 5.0 mongod instance."}],"name":"Downgrade Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Download the latest
<!-- -->
5.0
<!-- -->
binaries.
<a class="headerlink leafygreen-ui-1kepx47" href="#download-the-latest--binaries." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-the-latest--binaries.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Using either a package manager or a manual download, get the
latest patch release in the
<!-- -->
5.0
<!-- -->
series. If using a
package manager, add a new repository for the
<!-- -->
5.0
<!-- -->
binaries, then perform the actual downgrade process.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replace the
<!-- -->
6.0
<!-- -->
binaries with the downloaded
<!-- -->
5.0
<!-- -->
binaries.
<a class="headerlink leafygreen-ui-1kepx47" href="#replace-the--binaries-with-the-downloaded--binaries." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replace-the--binaries-with-the-downloaded--binaries.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Ensure that the
<!-- -->
5.0
<!-- -->
binaries are in your System PATH. To
confirm your binary version, run the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --version","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --version</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The command output should indicate a 5.0-series release.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Shut down the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
instance.
<a class="headerlink leafygreen-ui-1kepx47" href="#shut-down-the-mongod-instance." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shut-down-the-mongod-instance.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To shut down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to connect to the deployment and run the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { shutdown: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">shutdown</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update configuration files.
<a class="headerlink leafygreen-ui-1kepx47" href="#update-configuration-files." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-configuration-files.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Disable any configurable
<!-- -->
6.0
<!-- -->
features by updating the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance's configuration file before
restarting.
</p>
<p class="leafygreen-ui-1kp3ins">
To see the list of configurable
<!-- -->
6.0
<!-- -->
features, review the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0/#std-label-release-notes-6.0">
6.0 Release Notes
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
5
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Restart with the latest
<!-- -->
5.0
<!-- -->
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
instance.
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-with-the-latest--mongod-instance." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-with-the-latest--mongod-instance.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To start a
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
process, run the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --dbpath ","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod <!-- -->-<!-- -->-<!-- -->dbpath <!-- --><<!-- -->/<!-- -->path<!-- -->-<!-- -->to<!-- -->-<!-- -->data<!-- -->-<!-- -->folder<!-- -->></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To learn more about starting a
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
process, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-mongodb-processes/#std-label-start-mongod-processes">
Start
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
Processes
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$setOnInsert
<a class="headerlink leafygreen-ui-1kepx47" href="#-setoninsert" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-setoninsert">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="update">
<dt>
<code class="leafygreen-ui-1l06pbn">
$setOnInsert
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-update-up.-setOnInsert" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-update-up.-setOnInsert">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
If an update operation with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.update/#std-label-upsert-parameter">
upsert: true
</a>
results in an insert of a document, then
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-setOnInsert" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setOnInsert
</code>
</span>
</a>
assigns the specified values to the fields in the document. If the
update operation does not result in an insert,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-setOnInsert" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setOnInsert
</code>
</span>
</a>
does nothing.
</p>
<p class="leafygreen-ui-1kp3ins">
You can specify the
<code class="leafygreen-ui-1l06pbn">
upsert
</code>
option for:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#mongodb-method-db.collection.updateMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateMany()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify">
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</a>
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.updateOne(\n <query>,\n { $setOnInsert: { <field1>: <value1>, ... } },\n { upsert: true }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <<!-- -->query<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$setOnInsert</span>: <!-- -->{ <<!-- -->field1<!-- -->><!-- -->: <<!-- -->value1<!-- -->><!-- -->,<!-- --> <!-- -->...<!-- --> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To specify a
<code class="leafygreen-ui-1l06pbn">
<field>
</code>
in an embedded document or in an array, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/document/#std-label-document-dot-notation">
dot notation
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, update operators process document fields with
string-based names in lexicographic order. Fields with numeric names are
processed in numeric order. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/#std-label-update-operators-processing-order">
Update Operators Behavior
</a>
for details.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
no longer raises an
error when you use an update operator like
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-setOnInsert" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setOnInsert
</code>
</span>
</a>
with an empty operand expression (
<code class="leafygreen-ui-1l06pbn">
{ }
</code>
). An empty update results
in no changes and no
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
entry is created (meaning that the
operation is a no-op).
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
products
</code>
collection contains no documents.
</p>
<p class="leafygreen-ui-1kp3ins">
Insert a new document using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
</a>
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.update/#std-label-upsert-parameter">
upsert:
true
</a>
parameter.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products.updateOne(\n { _id: 1 },\n {\n $set: { item: \"apple\" },\n $setOnInsert: { defaultQty: 100 }\n },\n { upsert: true }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">products</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"apple"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$setOnInsert</span>: <!-- -->{ <span class="lg-highlight-attr">defaultQty</span>: <span class="lg-highlight-number">100</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB uses
<code class="leafygreen-ui-1l06pbn">
<query>
</code>
to create a new document with
<code class="leafygreen-ui-1l06pbn">
_id: 1
</code>
.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-setOnInsert" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setOnInsert
</code>
</span>
</a>
updates the document as specified.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
products
</code>
collection contains the newly-inserted document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"apple\", \"defaultQty\" : 100 }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"apple"</span>, <span class="lg-highlight-string">"defaultQty"</span> <!-- -->: <span class="lg-highlight-number">100</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.update/#std-label-upsert-parameter">
upsert
</a>
parameter is
<code class="leafygreen-ui-1l06pbn">
true
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
:
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
creates a new document
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
applies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/set/#mongodb-update-up.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
</a>
operation
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
applies the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-setOnInsert" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setOnInsert
</code>
</span>
</a>
operation
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
</a>
matches an existing document,
MongoDB only applies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/set/#mongodb-update-up.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
</a>
operation.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify">
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$allElementsTrue (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-allelementstrue--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-allelementstrue--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$allElementsTrue
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-allElementsTrue" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-allElementsTrue">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Evaluates an array as a set and returns
<code class="leafygreen-ui-1l06pbn">
true
</code>
if
<em>
no
</em>
element in
the array is
<code class="leafygreen-ui-1l06pbn">
false
</code>
. Otherwise, returns
<code class="leafygreen-ui-1l06pbn">
false
</code>
. An empty array
returns
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-allElementsTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$allElementsTrue
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $allElementsTrue: [ <expression> ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$allElementsTrue</span>: <!-- -->[ <<!-- -->expression<!-- -->> <!-- -->] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
<expression>
</code>
itself must resolve to an array, separate from
the outer array that denotes the argument list. For more information
on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If a set contains a nested array element,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-allElementsTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$allElementsTrue
</code>
</span>
</a>
does
<em>
not
</em>
descend
into the nested array but evaluates the array at top-level.
</p>
<p class="leafygreen-ui-1kp3ins">
In addition to the
<code class="leafygreen-ui-1l06pbn">
false
</code>
boolean value,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-allElementsTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$allElementsTrue
</code>
</span>
</a>
evaluates
as
<code class="leafygreen-ui-1l06pbn">
false
</code>
the following:
<code class="leafygreen-ui-1l06pbn">
null
</code>
,
<code class="leafygreen-ui-1l06pbn">
0
</code>
, and
<code class="leafygreen-ui-1l06pbn">
undefined
</code>
values. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-allElementsTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$allElementsTrue
</code>
</span>
</a>
evaluates all other values as
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
including non-zero numeric values and arrays.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:70%"/>
<col style="width:15%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Result
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $allElementsTrue: [ [ true, 1, "someString" ] ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
true
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $allElementsTrue: [ [ [ false ] ] ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
true
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $allElementsTrue: [ [ ] ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
true
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $allElementsTrue: [ [ null, false, 0 ] ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
false
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Create an example collection named
<code class="leafygreen-ui-1l06pbn">
survey
</code>
with the following
documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.survey.insertMany([\n { \"_id\" : 1, \"responses\" : [ true ] },\n { \"_id\" : 2, \"responses\" : [ true, false ] },\n { \"_id\" : 3, \"responses\" : [ ] },\n { \"_id\" : 4, \"responses\" : [ 1, true, \"seven\" ] },\n { \"_id\" : 5, \"responses\" : [ 0 ] },\n { \"_id\" : 6, \"responses\" : [ [ ] ] },\n { \"_id\" : 7, \"responses\" : [ [ 0 ] ] },\n { \"_id\" : 8, \"responses\" : [ [ false ] ] },\n { \"_id\" : 9, \"responses\" : [ null ] },\n { \"_id\" : 10, \"responses\" : [ undefined ] }\n])","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">survey</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">true</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-literal">false</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <!-- -->] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"seven"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">0</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <!-- -->[ <!-- -->] ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <!-- -->[ <span class="lg-highlight-number">0</span> ] ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">8</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <!-- -->[ <span class="lg-highlight-literal">false</span> ] ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">9</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">null</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">undefined</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-allElementsTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$allElementsTrue
</code>
</span>
</a>
operator to determine if the
<code class="leafygreen-ui-1l06pbn">
responses
</code>
array only contains values
that evaluate to
<code class="leafygreen-ui-1l06pbn">
true
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.survey.aggregate(\n [\n { $project: { responses: 1, isAllTrue: { $allElementsTrue: [ \"$responses\" ] }, _id: 0 } }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">survey</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">responses</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">isAllTrue</span>: <!-- -->{ <span class="lg-highlight-attr">$allElementsTrue</span>: <!-- -->[ <span class="lg-highlight-string">"$responses"</span> ] }<!-- -->, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following results:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"responses\" : [ true ], \"isAllTrue\" : true }\n{ \"responses\" : [ true, false ], \"isAllTrue\" : false }\n{ \"responses\" : [ ], \"isAllTrue\" : true }\n{ \"responses\" : [ 1, true, \"seven\" ], \"isAllTrue\" : true }\n{ \"responses\" : [ 0 ], \"isAllTrue\" : false }\n{ \"responses\" : [ [ ] ], \"isAllTrue\" : true }\n{ \"responses\" : [ [ 0 ] ], \"isAllTrue\" : true }\n{ \"responses\" : [ [ false ] ], \"isAllTrue\" : true }\n{ \"responses\" : [ null ], \"isAllTrue\" : false }\n{ \"responses\" : [ undefined ], \"isAllTrue\" : false }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">true</span> ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-literal">false</span> ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <!-- -->]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"seven"</span> ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">0</span> ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <!-- -->[ <!-- -->] ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <!-- -->[ <span class="lg-highlight-number">0</span> ] ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <!-- -->[ <span class="lg-highlight-literal">false</span> ] ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">null</span> ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"responses"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">undefined</span> ]<!-- -->, <span class="lg-highlight-string">"isAllTrue"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/troubleshoot-sharded-clusters/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Troubleshoot Sharded Clusters
<a class="headerlink leafygreen-ui-1kepx47" href="#troubleshoot-sharded-clusters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="troubleshoot-sharded-clusters">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#before-you-begin" target="_self">
<span>
Before You Begin
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#application-servers-or--instances-become-unavailable" target="_self">
<span>
Application Servers or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="">
<span>
<code class="leafygreen-ui-1l06pbn">
</code>
</span>
</a>
Instances Become Unavailable
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#a-single-member-becomes-unavailable-in-a-shard-replica-set" target="_self">
<span>
A Single Member Becomes Unavailable in a Shard Replica Set
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#all-members-of-a-shard-become-unavailable" target="_self">
<span>
All Members of a Shard Become Unavailable
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#a-config-server-replica-set-member-become-unavailable" target="_self">
<span>
A Config Server Replica Set Member Become Unavailable
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#cursor-fails-because-of-stale-config-data" target="_self">
<span>
Cursor Fails Because of Stale Config Data
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#shard-keys" target="_self">
<span>
Shard Keys
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#cluster-availability" target="_self">
<span>
Cluster Availability
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#config-database-string-error" target="_self">
<span>
Config Database String Error
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#avoid-downtime-when-moving-config-servers" target="_self">
<span>
Avoid Downtime when Moving Config Servers
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#movechunk-commit-failed-error" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
moveChunk commit failed
</code>
Error
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#inconsistent-sharding-metadata" target="_self">
<span>
Inconsistent Sharding Metadata
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
This page describes common strategies for troubleshooting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster
</a>
deployments.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Before You Begin
<a class="headerlink leafygreen-ui-1kepx47" href="#before-you-begin" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="before-you-begin">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-directShardOperations">
<code class="leafygreen-ui-1l06pbn">
directShardOperations
</code>
</a>
role to perform maintenance operations
that require you to execute commands directly against a shard.
</p>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Running commands using the
<code class="leafygreen-ui-1l06pbn">
directShardOperations
</code>
role can cause
your cluster to stop working correctly and may cause data corruption.
Only use the
<code class="leafygreen-ui-1l06pbn">
directShardOperations
</code>
role for maintenance purposes
or under the guidance of MongoDB support. Once you are done
performing maintenance operations, stop using the
<code class="leafygreen-ui-1l06pbn">
directShardOperations
</code>
role.
</p>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Application Servers or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
Instances Become Unavailable
<a class="headerlink leafygreen-ui-1kepx47" href="#application-servers-or--instances-become-unavailable" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="application-servers-or--instances-become-unavailable">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If each application server has its own
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance, other
application servers can continue to access the database. Furthermore,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances do not maintain persistent state, and they
can restart and become unavailable without losing any state or data.
When a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance starts, it retrieves a copy of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-config-database">
config database
</a>
and can begin routing queries.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
A Single Member Becomes Unavailable in a Shard Replica Set
<a class="headerlink leafygreen-ui-1kepx47" href="#a-single-member-becomes-unavailable-in-a-shard-replica-set" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="a-single-member-becomes-unavailable-in-a-shard-replica-set">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication">
Replica sets
</a>
provide
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-high-availability">
high availability
</a>
for
shards. If the unavailable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
,
then the replica set will
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-elections">
elect
</a>
a new
primary. If the unavailable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
, and it disconnects the primary and secondary will
continue to hold all data. In a three member replica set, even if a
single member of the set experiences catastrophic failure, two other
members have full copies of the data.
<a class="footnote-reference header-buffer" href="#footnote-recovery-window" id="ref-recovery-window-id1">
[1]
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Always investigate availability interruptions and failures. If a system
is unrecoverable, replace it and create a new member of the replica set
as soon as possible to replace the lost redundancy.
</p>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-recovery-window" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<a href="#ref-recovery-window-id1">
1
</a>
]
</td>
<td class="leafygreen-ui-17r2xs0">
If an unavailable secondary becomes available
while it still has current oplog entries, it can catch up to the
latest state of the set using the normal
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sync">
replication process
</a>
; otherwise, it must perform an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-initial-sync">
initial sync.
</a>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
All Members of a Shard Become Unavailable
<a class="headerlink leafygreen-ui-1kepx47" href="#all-members-of-a-shard-become-unavailable" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="all-members-of-a-shard-become-unavailable">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In a sharded cluster,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances
monitor the replica sets in the sharded cluster (e.g. shard replica
sets, config server replica set).
</p>
<p class="leafygreen-ui-1kp3ins">
If all members of a replica set shard are unavailable, all data held in
that shard is unavailable. However, the data on all other shards will
remain available, and it is possible to read and write data to the
other shards. However, your application must be able to deal with
partial results, and you should investigate the cause of the
interruption and attempt to recover the shard as soon as possible.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-config-servers-and-availability">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
A Config Server Replica Set Member Become Unavailable
<a class="headerlink leafygreen-ui-1kepx47" href="#a-config-server-replica-set-member-become-unavailable" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="a-config-server-replica-set-member-become-unavailable">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Replica sets provide
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-high-availability">
high availability
</a>
for
the config servers. If an unavailable config server is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
, then the replica set will
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-elections">
elect
</a>
a new primary.
</p>
<p class="leafygreen-ui-1kp3ins">
If the replica set config server loses its primary and cannot elect a
primary, the cluster's metadata becomes
<em>
read only
</em>
. You can still read
and write data from the shards, but no
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
chunk migration
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/split-chunks-in-sharded-cluster/">
chunk splits
</a>
will occur until a primary
is available.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Distributing replica set members across two data centers provides
benefit over a single data center. In a two data center
distribution,
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If one of the data centers goes down, the data is still available
for reads unlike a single data center distribution.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the data center with a minority of the members goes down, the
replica set can still serve write operations as well as read
operations.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
However, if the data center with the majority of the members goes
down, the replica set becomes read-only.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If possible, distribute members across at least three data centers.
For config server replica sets (CSRS), the best practice is to
distribute across three (or more depending on the number of members)
centers. If the cost of the third data center is prohibitive, one
distribution possibility is to evenly distribute the data bearing
members across the two data centers and store the remaining member
in the cloud if your company policy allows.
</p>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
All config servers must be running and available when you first initiate
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster.
</a>
</p>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Cursor Fails Because of Stale Config Data
<a class="headerlink leafygreen-ui-1kepx47" href="#cursor-fails-because-of-stale-config-data" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="cursor-fails-because-of-stale-config-data">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
A query returns the following warning when one or more of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances has not yet updated its cache of the
cluster's metadata from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-config-database">
config database:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"could not initialize cursor across all shards because : stale config detected"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">could not initialize cursor across all shards because : stale config detected</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This warning
<em>
should
</em>
not propagate back to your application. The
warning will repeat until all the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances refresh
their caches. To force an instance to refresh its cache, run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/flushRouterConfig/#mongodb-dbcommand-dbcmd.flushRouterConfig">
<code class="leafygreen-ui-1l06pbn">
flushRouterConfig
</code>
</a>
command.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Shard Keys
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-keys" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shard-keys">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To troubleshoot a shard key, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-troubleshooting-shard-keys/#std-label-shardkey-troubleshoot-shard-keys">
Troubleshoot Shard Keys.
</a>
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Cluster Availability
<a class="headerlink leafygreen-ui-1kepx47" href="#cluster-availability" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="cluster-availability">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To ensure cluster availability:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Each shard should be a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
, if a specific
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance fails, the replica set members will elect
another to be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
and continue operation. However, if an
entire shard is unreachable or fails for some reason, that data will
be unavailable.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The shard key should allow the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
to isolate most
operations to a single shard. If operations can be processed by a
single shard, the failure of a single shard will only render
<em>
some
</em>
data unavailable. If operations need to access all shards for queries,
the failure of a single shard will render the entire cluster
unavailable.
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-config-database-string-error">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Config Database String Error
<a class="headerlink leafygreen-ui-1kepx47" href="#config-database-string-error" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="config-database-string-error">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Config servers must be deployed as replica
sets. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances for the sharded cluster must
specify the same config server replica set name but can specify
hostname and port of different members of the replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
With earlier versions of MongoDB sharded clusters that use the topology
of three mirrored
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances for config servers,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances in a sharded cluster must specify identical
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-sharding.configDB">
<code class="leafygreen-ui-1l06pbn">
configDB
</code>
</a>
string.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Avoid Downtime when Moving Config Servers
<a class="headerlink leafygreen-ui-1kepx47" href="#avoid-downtime-when-moving-config-servers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="avoid-downtime-when-moving-config-servers">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Use CNAMEs to identify your config servers to the cluster so
that you can rename and renumber your config servers without downtime.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
<code class="leafygreen-ui-1l06pbn">
moveChunk commit failed
</code>
Error
<a class="headerlink leafygreen-ui-1kepx47" href="#movechunk-commit-failed-error" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="movechunk-commit-failed-error">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
At the end of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration">
chunk migration
</a>
, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard">
shard
</a>
must connect to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-config-database">
config database
</a>
to update the
chunk's record in the cluster metadata. If the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard">
shard
</a>
fails to
connect to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-config-database">
config database
</a>
, MongoDB reports the following
error:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ERROR: moveChunk commit failed: version is at <n>|<nn> instead of\n<n>|<nn>\" and \"ERROR: TERMINATING\""}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">ERROR: moveChunk commit failed: version is at <n>|<nn> instead of</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><N>|<NN>" and "ERROR: TERMINATING"</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When this happens, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
member of the shard's replica
set then terminates to protect data consistency. If a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
member can access the config database, data on the shard becomes
accessible again after an election.
</p>
<p class="leafygreen-ui-1kp3ins">
The user will need to resolve the chunk migration failure
independently. If you encounter this issue, ask the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://community.mongodb.com/?tck=docs_server" target="_self">
<span>
MongoDB
Community
</span>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/support/#std-label-technical-support">
MongoDB Support
</a>
to address this issue.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Inconsistent Sharding Metadata
<a class="headerlink leafygreen-ui-1kepx47" href="#inconsistent-sharding-metadata" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="inconsistent-sharding-metadata">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/checkMetadataConsistency/#mongodb-dbcommand-dbcmd.checkMetadataConsistency">
<code class="leafygreen-ui-1l06pbn">
checkMetadataConsistency
</code>
</a>
command
is available to check sharding metadata for inconsistencies and corruptions
due to bugs in previous releases of MongoDB.
</p>
<p class="leafygreen-ui-1kp3ins">
Inconsistencies in sharding metadata can originate in cases such as:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Clusters upgraded from a pre-5.0 release of MongoDB that may have
corrupted data from past DDL operations.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Manual interventions, such as manipulating the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/config-database/#std-label-config-database">
Config Database
</a>
or bypassing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
to write directly to a shard.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Maintenance operations, such as upgrade or downgrade procedures.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
These inconsistencies can result in incorrect query results
or data loss.
</p>
<p class="leafygreen-ui-1kp3ins">
To check sharding metadata for inconsistencies, run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/checkMetadataConsistency/#mongodb-dbcommand-dbcmd.checkMetadataConsistency">
<code class="leafygreen-ui-1l06pbn">
checkMetadataConsistency
</code>
</a>
command:
</p>
<div class="css-1f5771r">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand( { checkMetadataConsistency: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>( { <span class="lg-highlight-attr">checkMetadataConsistency</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<div class="css-9st569 efa38qy0" style="--border-color: #E8EDEB;">
<button aria-disabled="false" class="lg-ui-button-0000 leafygreen-ui-hix6y6" data-lgid="lg-button" role="button" type="button">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg alt="" aria-hidden="true" class="leafygreen-ui-hjnzs9" fill="none" height="16" role="presentation" viewbox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
<path clip-rule="evenodd" d="M14.364 10.778a1 1 0 0 0 0-1.414l-4.95-4.95-.707-.707a1 1 0 0 0-1.414 0l-.707.707-4.95 4.95a1 1 0 0 0 0 1.414l.707.707a1 1 0 0 0 1.414 0L8 7.243l4.243 4.242a1 1 0 0 0 1.414 0l.707-.707Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
HIDE OUTPUT
</div>
</button>
</div>
<div class="leafygreen-ui-1oteowz">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n cursor: {\n id: Long(\"0\"),\n ns: \"test.$cmd.aggregate\",\n firstBatch: [\n {\n type: \"MisplacedCollection\",\n description: \"Unsharded collection found on shard different from database primary shard\",\n details: {\n namespace: \"test.authors\",\n shard: \"shard02\",\n localUUID: new UUID(\"1ad56770-61e2-48e9-83c6-8ecefe73cfc4\")\n }\n }\n ],\n },\n ok: 1\n}","programmingLanguage":"JSON"}
</script>
<div class="css-1sax7hu e11q6jfk0" style="--code-container-border: initial; --code-pre-border: none;">
<div class="leafygreen-ui-1fyvhqe">
<div class="leafygreen-ui-1ij019s">
<pre class="leafygreen-ui-12cejcz" tabindex="0"><code class="lg-highlight-hljs-dark json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> cursor<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> id<span class="lg-highlight-punctuation">:</span> Long(<span class="lg-highlight-string">"0"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ns<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"test.$cmd.aggregate"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> firstBatch<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> type<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"MisplacedCollection"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> description<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Unsharded collection found on shard different from database primary shard"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> details<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> namespace<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"test.authors"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> shard<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"shard02"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> localUUID<span class="lg-highlight-punctuation">:</span> new UUID(<span class="lg-highlight-string">"1ad56770-61e2-48e9-83c6-8ecefe73cfc4"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">]</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ok<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Documents returned by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/checkMetadataConsistency/#mongodb-dbcommand-dbcmd.checkMetadataConsistency">
<code class="leafygreen-ui-1l06pbn">
checkMetadataConsistency
</code>
</a>
command indicate
the inconsistencies identified by MongoDB in the sharding metadata of the
cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
For information on inconsistency documents returned by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/checkMetadataConsistency/#mongodb-dbcommand-dbcmd.checkMetadataConsistency">
<code class="leafygreen-ui-1l06pbn">
checkMetadataConsistency
</code>
</a>
command, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/inconsistency-type/#std-label-inconsistency-types">
Inconsistency Types.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/release-notes/5.0-upgrade-sharded-cluster/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Upgrade a Sharded Cluster to 5.0
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-a-sharded-cluster-to-5.0" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-a-sharded-cluster-to-5.0">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#upgrade-recommendations-and-checklists" target="_self">
<span>
Upgrade Recommendations and Checklists
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#prerequisites" target="_self">
<span>
Prerequisites
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#download-newversion-binaries" target="_self">
<span>
Download
<!-- -->
5.0
<!-- -->
Binaries
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#upgrade-process" target="_self">
<span>
Upgrade Process
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-upgrade-procedures" target="_self">
<span>
Additional Upgrade Procedures
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Use this tutorial to upgrade from MongoDB
<!-- -->
4.4
<!-- -->
to MongoDB
<!-- -->
5.0
<!-- -->
. To upgrade to a new patch release within the same release
series, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/upgrade-revision/#std-label-upgrade-to-latest-revision">
Upgrade to the Latest Self-Managed Patch Release of MongoDB
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Familiarize yourself with the content of this document, including
thoroughly reviewing the prerequisites, prior to upgrading to MongoDB
<!-- -->
5.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
The following steps outline the procedure to upgrade a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
that is a shard member from version
<!-- -->
4.4
<!-- -->
to
<!-- -->
5.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
If you need guidance on upgrading to
<!-- -->
5.0
<!-- -->
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/products/consulting?tck=docs_server" target="_self">
<span>
MongoDB
professional services
</span>
</a>
offer major version upgrade support to help ensure a smooth transition
without interruption to your MongoDB application.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Upgrade Recommendations and Checklists
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-recommendations-and-checklists" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-recommendations-and-checklists">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When upgrading, consider the following:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Upgrade Version Path
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-version-path" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-version-path">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To upgrade an existing MongoDB deployment to
<!-- -->
5.0
<!-- -->
, you must be
running a
<!-- -->
4.4-series
<!-- -->
release.
</p>
<p class="leafygreen-ui-1kp3ins">
To upgrade from a version earlier than the
<!-- -->
4.4-series
<!-- -->
, you must
successively upgrade major releases until you have upgraded to
<!-- -->
4.4-series
<!-- -->
. For example, if you are running a
<!-- -->
4.2-series
<!-- -->
, you must
<!-- -->
upgrade first to 4.4
<!-- -->
<em>
before
</em>
you can upgrade to
<!-- -->
5.0
<!-- -->
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Check Driver Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#check-driver-compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="check-driver-compatibility">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Before you upgrade MongoDB, check that you're using a MongoDB
<!-- -->
5.0
<!-- -->
-compatible driver. Consult the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver documentation
</span>
</a>
for your specific driver to verify
compatibility with MongoDB
<!-- -->
5.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
Upgraded deployments that run on incompatible drivers might encounter
unexpected or undefined behavior.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Preparedness
<a class="headerlink leafygreen-ui-1kepx47" href="#preparedness" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="preparedness">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Before beginning your upgrade, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0-compatibility/">
Compatibility Changes in MongoDB 5.0
</a>
document to
ensure that your applications and deployments are compatible with
MongoDB
<!-- -->
5.0
<!-- -->
. Resolve the incompatibilities in your deployment
before starting the upgrade.
</p>
<p class="leafygreen-ui-1kp3ins">
Before upgrading MongoDB, always test your application in a staging
environment before deploying the upgrade to your production
environment.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Downgrade Consideration
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-consideration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="downgrade-consideration">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You cannot downgrade your deployment's binary version without assistance from
support.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/8.0-downgrade/#std-label-8.0-downgrade">
Downgrade
<!-- -->
8.0
<!-- -->
to
<!-- -->
7.0
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Prerequisites
<a class="headerlink leafygreen-ui-1kepx47" href="#prerequisites" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="prerequisites">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Before you upgrade your sharded cluster, check the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0/#std-label-5.0-rel-notes-performance">
5.0 Performance Considerations
</a>
for any
potential performance impacts when upgrading to
<!-- -->
5.0
<!-- -->
.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Ensure TTL Config is Valid
<a class="headerlink leafygreen-ui-1kepx47" href="#ensure-ttl-config-is-valid" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ensure-ttl-config-is-valid">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Ensure that the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/expire-data/#std-label-ttl-collections">
TTL
</a>
configuration is valid.
Before upgrading, remove or correct any TTL indexes that have
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
set to
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
. In MongoDB 5.0 and later,
setting
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
to
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
has the same effect as
setting
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
to
<code class="leafygreen-ui-1l06pbn">
0
</code>
. For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0-compatibility/#std-label-ttl_expireAfterSeconds_behavior">
TTL
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
Behavior When Set to
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
All Members Version
<a class="headerlink leafygreen-ui-1kepx47" href="#all-members-version" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="all-members-version">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To upgrade a sharded cluster to
<!-- -->
5.0
<!-- -->
,
<strong>
all
</strong>
members of the
cluster must be at least version
<!-- -->
4.4
<!-- -->
. The upgrade process
checks all components of the cluster and will produce warnings if any
component is running version earlier than
<!-- -->
4.4
<!-- -->
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Confirm Clean Shutdown
<a class="headerlink leafygreen-ui-1kepx47" href="#confirm-clean-shutdown" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="confirm-clean-shutdown">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Prior to upgrading a member of the sharded cluster, confirm that the
member was
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-mongodb-processes/#std-label-terminate-mongod-processes">
cleanly shut down
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Feature Compatibility Version
<a class="headerlink leafygreen-ui-1kepx47" href="#feature-compatibility-version" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="feature-compatibility-version">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
4.4
<!-- -->
sharded cluster must have
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
set to
<code class="leafygreen-ui-1l06pbn">
"4.4"
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
To ensure that all members of the sharded cluster have
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
set to
<code class="leafygreen-ui-1l06pbn">
"4.4"
</code>
, connect to each
shard replica set member and each config server replica set member
and check the
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
:
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
For a sharded cluster that has access control enabled, to run the
following command against a shard replica set member, you must
connect to the member as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-users/#std-label-shard-local-users">
shard local user
<!-- -->
.
</a>
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">getParameter</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">featureCompatibilityVersion</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
All members should return a result that includes
<code class="leafygreen-ui-1l06pbn">
"featureCompatibilityVersion" : { "version" : "4.4" }
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
To set or update
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
, run the
following command on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { setFeatureCompatibilityVersion: \"4.4\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">setFeatureCompatibilityVersion</span>: <span class="lg-highlight-string">"4.4"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replica Set Member State
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-member-state" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replica-set-member-state">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For shards and config servers, ensure that no replica set member is in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.ROLLBACK">
<code class="leafygreen-ui-1l06pbn">
ROLLBACK
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.RECOVERING">
<code class="leafygreen-ui-1l06pbn">
RECOVERING
</code>
</a>
state.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Back up the
<code class="leafygreen-ui-1l06pbn">
config
</code>
Database
<a class="headerlink leafygreen-ui-1kepx47" href="#back-up-the-config-database" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="back-up-the-config-database">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional but Recommended.
</em>
As a precaution, take a backup of the
<code class="leafygreen-ui-1l06pbn">
config
</code>
database
<em>
before
</em>
upgrading the sharded cluster.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Download
<!-- -->
5.0
<!-- -->
Binaries
<a class="headerlink leafygreen-ui-1kepx47" href="#download-newversion-binaries" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-newversion-binaries">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use Package Manager
<a class="headerlink leafygreen-ui-1kepx47" href="#use-package-manager" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-package-manager">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you installed MongoDB from the MongoDB
<code class="leafygreen-ui-1l06pbn">
apt
</code>
,
<code class="leafygreen-ui-1l06pbn">
yum
</code>
,
<code class="leafygreen-ui-1l06pbn">
dnf
</code>
, or
<code class="leafygreen-ui-1l06pbn">
zypper
</code>
repositories, you should upgrade to
<!-- -->
5.0
<!-- -->
using your package
manager.
</p>
<p class="leafygreen-ui-1kp3ins">
Follow the appropriate
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
5.0 installation instructions
</a>
for your Linux system. This
will involve adding a repository for the new release, then performing
the actual upgrade process.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Download
<!-- -->
5.0
<!-- -->
Binaries Manually
<a class="headerlink leafygreen-ui-1kepx47" href="#download-newversion-binaries-manually" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-newversion-binaries-manually">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you have not installed MongoDB using a package manager, you can
manually download the MongoDB binaries from the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/try/download?tck=docs_server" target="_self">
<span>
MongoDB Download
Center
</span>
</a>
.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
5.0 installation instructions
</a>
for more information.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Upgrade Process
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-process" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-process">
</div>
</a>
</h2>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Disable the Balancer.Connect mongosh to a mongos instance in\nthe sharded cluster, and run sh.stopBalancer() to\ndisable the balancer:If a migration is in progress, the system will complete the\nin-progress migration before stopping the balancer. You can run\nsh.isBalancerRunning() to check the balancer's current\nstate.To verify that the balancer is disabled, run\nsh.getBalancerState(), which returns false if the balancer\nis disabled:For more information on disabling the balancer, see\nDisable the Balancer."},{"@type":"HowToStep","text":"Upgrade the config servers.Upgrade the secondary\nmembers of the replica set one at a time:Shut down the secondary mongod instance and replace\nthe 4.4 binary with the 5.0 binary.Start the 5.0 binary with the --configsvr,\n--replSet, and --port.\nInclude any other options as used by the deployment.If using a configuration file, update the file to\nspecify sharding.clusterRole: configsvr, replication.replSetName,\nnet.port, and net.bindIp,\nthen start the 5.0 binary:Include any other settings as appropriate for your deployment.Wait for the member to recover to SECONDARY state before\nupgrading the next secondary member. To check the member's state,\nissue rs.status() in mongosh.Repeat for each secondary member.Step down the replica set primary.Connect mongosh to the primary and use\nrs.stepDown() to step down the primary and force an\nelection of a new primary:When rs.status() shows that the primary has stepped\ndown and another member has assumed PRIMARY state, shut down\nthe stepped-down primary and replace the mongod binary\nwith the 5.0 binary.Start the 5.0 binary with the --configsvr, --replSet,\n--port, and --bind_ip options. Include any optional command line\noptions used by the previous deployment:If using a configuration file, update the file to\nspecify sharding.clusterRole: configsvr, replication.replSetName,\nnet.port, and net.bindIp,\nthen start the 5.0 binary:Include any other configuration as appropriate for your deployment."},{"@type":"HowToStep","text":"Upgrade the shards.Upgrade the shards one at a time.For each shard replica set:Upgrade the secondary\nmembers of the replica set one at a time:Shut down the mongod instance and replace the 4.4\nbinary with the 5.0 binary.Start the 5.0 binary with the --shardsvr, --replSet,\n--port, and --bind_ip options. Include any additional command line\noptions as appropriate for your deployment:If using a configuration file, update the file to\ninclude sharding.clusterRole: shardsvr,\nreplication.replSetName, net.port, and\nnet.bindIp, then start the 5.0 binary:Include any other configuration as appropriate for your deployment.Wait for the member to recover to SECONDARY state before\nupgrading the next secondary member. To check the member's\nstate, you can issue rs.status() in\nmongosh.Repeat for each secondary member.Step down the replica set primary.Connect mongosh to the primary and use\nrs.stepDown() to step down the primary\nand force an election of a new primary:When rs.status()\nshows that the primary has stepped down and another member\nhas assumed PRIMARY state, upgrade the stepped-down primary:Shut down the stepped-down primary and replace the\nmongod binary with the 5.0 binary.Start the 5.0 binary with the --shardsvr, --replSet,\n--port, and --bind_ip options. Include any additional command line\noptions as appropriate for your deployment:If using a configuration file, update the file to\nspecify sharding.clusterRole: shardsvr, replication.replSetName,\nnet.port, and net.bindIp, then start the\n5.0 binary:Include any other configuration as appropriate for your deployment."},{"@type":"HowToStep","text":"Upgrade the mongos instances.Replace each mongos instance with the 5.0 binary\nand restart. Include any other configuration as appropriate for your\ndeployment.The --bind_ip option must be specified when\nthe sharded cluster members are run on different hosts or if\nremote clients connect to the sharded cluster."},{"@type":"HowToStep","text":"Re-enable the balancer.Using mongosh, connect to a\nmongos in the cluster and run\nsh.startBalancer() to re-enable the balancer:Starting in MongoDB 6.0.3, automatic chunk splitting is not performed.\nThis is because of balancing policy improvements. Auto-splitting commands\nstill exist, but do not perform an operation.In MongoDB versions earlier than 6.0.3, sh.startBalancer()\nalso enables auto-splitting for the sharded cluster.If you do not wish to enable auto-splitting while the balancer is\nenabled, you must also run sh.disableAutoSplit().For more information about re-enabling the balancer, see\nEnable the Balancer."},{"@type":"HowToStep","text":"Enable backwards-incompatible 5.0 features.At this point, you can run the 5.0 binaries without the\n5.0 features that are incompatible with 4.4.To enable these 5.0 features, set the feature compatibility\nversion (fCV) to 5.0.Enabling these backwards-incompatible features can complicate the\ndowngrade process since you must remove any persisted backwards-incompatible\nfeatures before you downgrade.It is recommended that after upgrading, you allow your deployment to run\nwithout enabling these features for a burn-in period to ensure the\nlikelihood of downgrade is minimal. When you are confident that the\nlikelihood of downgrade is minimal, enable these features.On a mongos instance, run the\nsetFeatureCompatibilityVersion command in the admin\ndatabase:Setting featureCompatibilityVersion (fCV) : \"5.0\"\nimplicitly performs a replSetReconfig on each shard to\nadd the term field to the shard replica configuration\ndocument.The command doesn't complete until the new configuration propagates to a\nmajority of replica set members.This command must perform writes to an internal system collection.\nIf for any reason the command does not complete successfully, you\ncan safely retry the command on the mongos as the\noperation is idempotent.While setFeatureCompatibilityVersion is running on\nthe sharded cluster, chunk migrations, splits, and merges\ncan fail with ConflictingOperationInProgress.Any orphaned documents that exist on your\nshards will be cleaned up when you set the\nsetFeatureCompatibilityVersion to 5.0. The\ncleanup process:Does not block the upgrade from completing, andIs rate limited. To mitigate the potential effect on performance\nduring orphaned document cleanup, see\nRange Deletion Performance Tuning.The mongos binary cannot connect to mongod\ninstances whose feature compatibility version (fCV) is greater\nthan that of the mongos. For example, you cannot connect\na MongoDB 4.4 version mongos to a 5.0\nsharded cluster with fCV set to 5.0. You\ncan, however, connect a MongoDB 4.4 version\nmongos to a 5.0 sharded cluster with fCV set to 4.4.Using substitutions, so that the blurb in example is updated per each version of the manual."}],"name":"Upgrade Process","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Disable the Balancer.
<a class="headerlink leafygreen-ui-1kepx47" href="#disable-the-balancer" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="disable-the-balancer">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance in
the sharded cluster, and run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.stopBalancer/#mongodb-method-sh.stopBalancer">
<code class="leafygreen-ui-1l06pbn">
sh.stopBalancer()
</code>
</a>
to
disable the balancer:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.stopBalancer()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">stopBalancer</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If a migration is in progress, the system will complete the
in-progress migration before stopping the balancer. You can run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.isBalancerRunning/#mongodb-method-sh.isBalancerRunning">
<code class="leafygreen-ui-1l06pbn">
sh.isBalancerRunning()
</code>
</a>
to check the balancer's current
state.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To verify that the balancer is disabled, run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.getBalancerState/#mongodb-method-sh.getBalancerState">
<code class="leafygreen-ui-1l06pbn">
sh.getBalancerState()
</code>
</a>
, which returns false if the balancer
is disabled:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.getBalancerState()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">getBalancerState</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on disabling the balancer, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharding-balancing-disable-temporarily">
Disable the Balancer
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Upgrade the config servers.
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-the-config-servers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-the-config-servers">
</div>
</a>
</h3>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Upgrade the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-members/#std-label-replica-set-secondary-members">
secondary
</a>
members of the replica set one at a time:
</p>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Shut down the secondary
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance and replace
the
<!-- -->
4.4
<!-- -->
binary with the
<!-- -->
5.0
<!-- -->
binary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Start the
<!-- -->
5.0
<!-- -->
binary with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configsvr">
<code class="leafygreen-ui-1l06pbn">
--configsvr
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--replSet">
<code class="leafygreen-ui-1l06pbn">
--replSet
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--port">
<code class="leafygreen-ui-1l06pbn">
--port
</code>
</a>
.
Include any other options as used by the deployment.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --configsvr --replSet <replsetname> --port <port> --dbpath <path> --bind_ip localhost,<ip>","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --configsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
</a>
, update the file to
specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-sharding.clusterRole">
<code class="leafygreen-ui-1l06pbn">
sharding.clusterRole: configsvr
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.port">
<code class="leafygreen-ui-1l06pbn">
net.port
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</a>
,
then start the
<!-- -->
5.0
<!-- -->
binary:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sharding:\n clusterRole: configsvr\nreplication:\n replSetName: <string>\nnet:\n port: <port>\n bindIp: localhost,<ip>\nstorage:\n dbpath: <path>","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">sharding:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterRole:</span> <span class="lg-highlight-string">configsvr</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSetName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">port:</span> <span class="lg-highlight-string"><port></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-string">localhost,<ip</span> <span class="lg-highlight-string">address></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbpath:</span> <span class="lg-highlight-string"><path></span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include any other settings as appropriate for your deployment.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Wait for the member to recover to
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
state before
upgrading the next secondary member. To check the member's state,
issue
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.status/#mongodb-method-rs.status">
<code class="leafygreen-ui-1l06pbn">
rs.status()
</code>
</a>
in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Repeat for each secondary member.
</p>
</li>
</ol>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Step down the replica set primary.
</p>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to the primary and use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.stepDown/#mongodb-method-rs.stepDown">
<code class="leafygreen-ui-1l06pbn">
rs.stepDown()
</code>
</a>
to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-step-down">
step down
</a>
the primary and force an
election of a new primary:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"rs.stepDown()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">rs.<span class="lg-highlight-title lg-highlight-function">stepDown</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.status/#mongodb-method-rs.status">
<code class="leafygreen-ui-1l06pbn">
rs.status()
</code>
</a>
shows that the primary has stepped
down and another member has assumed
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
state, shut down
the stepped-down primary and replace the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
binary
with the
<!-- -->
5.0
<!-- -->
binary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Start the
<!-- -->
5.0
<!-- -->
binary with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configsvr">
<code class="leafygreen-ui-1l06pbn">
--configsvr
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--replSet">
<code class="leafygreen-ui-1l06pbn">
--replSet
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--port">
<code class="leafygreen-ui-1l06pbn">
--port
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip">
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
</a>
options. Include any optional command line
options used by the previous deployment:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --configsvr --replSet <replsetname> --port <port> --dbpath <path> --bind_ip localhost,<ip>","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --configsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
</a>
, update the file to
specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-sharding.clusterRole">
<code class="leafygreen-ui-1l06pbn">
sharding.clusterRole: configsvr
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.port">
<code class="leafygreen-ui-1l06pbn">
net.port
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</a>
,
then start the
<!-- -->
5.0
<!-- -->
binary:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sharding:\n clusterRole: configsvr\nreplication:\n replSetName: <string>\nnet:\n port: <port>\n bindIp: localhost,<ip>\nstorage:\n dbpath: <path>","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">sharding:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterRole:</span> <span class="lg-highlight-string">configsvr</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSetName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">port:</span> <span class="lg-highlight-string"><port></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-string">localhost,<ip</span> <span class="lg-highlight-string">address></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbpath:</span> <span class="lg-highlight-string"><path></span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include any other configuration as appropriate for your deployment.
</p>
</li>
</ol>
</li>
</ol>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Upgrade the shards.
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-the-shards" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-the-shards">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Upgrade the shards one at a time.
</p>
<p class="leafygreen-ui-1kp3ins">
For each shard replica set:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Upgrade the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-members/#std-label-replica-set-secondary-members">
secondary
</a>
members of the replica set one at a time:
</p>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Shut down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance and replace the
<!-- -->
4.4
<!-- -->
binary with the
<!-- -->
5.0
<!-- -->
binary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Start the
<!-- -->
5.0
<!-- -->
binary with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--shardsvr">
<code class="leafygreen-ui-1l06pbn">
--shardsvr
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--replSet">
<code class="leafygreen-ui-1l06pbn">
--replSet
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--port">
<code class="leafygreen-ui-1l06pbn">
--port
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip">
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
</a>
options. Include any additional command line
options as appropriate for your deployment:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --shardsvr --replSet <replsetname> --port <port> --dbpath <path> --bind_ip localhost,<ip>","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --shardsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
</a>
, update the file to
include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-sharding.clusterRole">
<code class="leafygreen-ui-1l06pbn">
sharding.clusterRole: shardsvr
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.port">
<code class="leafygreen-ui-1l06pbn">
net.port
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</a>
, then start the
<!-- -->
5.0
<!-- -->
binary:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sharding:\n clusterRole: shardsvr\nreplication:\n replSetName: <string>\nnet:\n port: <port>\n bindIp: localhost,<ip>\nstorage:\n dbpath: <path>","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">sharding:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterRole:</span> <span class="lg-highlight-string">shardsvr</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSetName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">port:</span> <span class="lg-highlight-string"><port></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-string">localhost,<ip</span> <span class="lg-highlight-string">address></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbpath:</span> <span class="lg-highlight-string"><path></span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include any other configuration as appropriate for your deployment.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Wait for the member to recover to
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
state before
upgrading the next secondary member. To check the member's
state, you can issue
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.status/#mongodb-method-rs.status">
<code class="leafygreen-ui-1l06pbn">
rs.status()
</code>
</a>
in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Repeat for each secondary member.
</p>
</li>
</ol>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Step down the replica set primary.
</p>
<p class="leafygreen-ui-1kp3ins">
Connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to the primary and use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.stepDown/#mongodb-method-rs.stepDown">
<code class="leafygreen-ui-1l06pbn">
rs.stepDown()
</code>
</a>
to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-step-down">
step down
</a>
the primary
and force an election of a new primary:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"rs.stepDown()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">rs.<span class="lg-highlight-title lg-highlight-function">stepDown</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.status/#mongodb-method-rs.status">
<code class="leafygreen-ui-1l06pbn">
rs.status()
</code>
</a>
shows that the primary has stepped down and another member
has assumed
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
state, upgrade the stepped-down primary:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Shut down the stepped-down primary and replace the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
binary with the
<!-- -->
5.0
<!-- -->
binary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Start the
<!-- -->
5.0
<!-- -->
binary with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--shardsvr">
<code class="leafygreen-ui-1l06pbn">
--shardsvr
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--replSet">
<code class="leafygreen-ui-1l06pbn">
--replSet
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--port">
<code class="leafygreen-ui-1l06pbn">
--port
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip">
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
</a>
options. Include any additional command line
options as appropriate for your deployment:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --shardsvr --replSet <replsetname> --port <port> --dbpath <path> --bind_ip localhost,<ip>","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --shardsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
</a>
, update the file to
specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-sharding.clusterRole">
<code class="leafygreen-ui-1l06pbn">
sharding.clusterRole: shardsvr
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.port">
<code class="leafygreen-ui-1l06pbn">
net.port
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</a>
, then start the
<!-- -->
5.0
<!-- -->
binary:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sharding:\n clusterRole: shardsvr\nreplication:\n replSetName: <string>\nnet:\n port: <port>\n bindIp: localhost,<ip>\nstorage:\n dbpath: <path>","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">sharding:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterRole:</span> <span class="lg-highlight-string">shardsvr</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSetName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">port:</span> <span class="lg-highlight-string"><port></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-string">localhost,<ip</span> <span class="lg-highlight-string">address></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbpath:</span> <span class="lg-highlight-string"><path></span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include any other configuration as appropriate for your deployment.
</p>
</li>
</ol>
</li>
</ol>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Upgrade the
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
instances.
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-the-mongos-instances" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-the-mongos-instances">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Replace each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance with the
<!-- -->
5.0
<!-- -->
binary
and restart. Include any other configuration as appropriate for your
deployment.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--bind_ip">
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
</a>
option must be specified when
the sharded cluster members are run on different hosts or if
remote clients connect to the sharded cluster.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongos --configdb csReplSet/<rsconfigsver1:port1>,<rsconfigsver2:port2>,<rsconfigsver3:port3> --bind_ip localhost,<ip>","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongos --configdb csReplSet/<rsconfigsver1:port1>,<rsconfigsver2:port2>,<rsconfigsver3:port3> --bind_ip localhost,<ip address></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
5
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Re-enable the balancer.
<a class="headerlink leafygreen-ui-1kepx47" href="#re-enable-the-balancer" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="re-enable-the-balancer">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
, connect to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
in the cluster and run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.startBalancer/#mongodb-method-sh.startBalancer">
<code class="leafygreen-ui-1l06pbn">
sh.startBalancer()
</code>
</a>
to re-enable the balancer:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.startBalancer()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">startBalancer</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0.3, automatic chunk splitting is not performed.
This is because of balancing policy improvements. Auto-splitting commands
still exist, but do not perform an operation.
</p>
<p class="leafygreen-ui-1kp3ins">
In MongoDB versions earlier than 6.0.3,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.startBalancer/#mongodb-method-sh.startBalancer">
<code class="leafygreen-ui-1l06pbn">
sh.startBalancer()
</code>
</a>
also enables auto-splitting for the sharded cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
If you do not wish to enable auto-splitting while the balancer is
enabled, you must also run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.disableAutoSplit/#mongodb-method-sh.disableAutoSplit">
<code class="leafygreen-ui-1l06pbn">
sh.disableAutoSplit()
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about re-enabling the balancer, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharding-balancing-enable">
Enable the Balancer
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
6
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Enable backwards-incompatible
<!-- -->
5.0
<!-- -->
features.
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-backwards-incompatible-features" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enable-backwards-incompatible-features">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
At this point, you can run the
<!-- -->
5.0
<!-- -->
binaries without the
<!-- -->
5.0
<!-- -->
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0-compatibility/#std-label-5.0-compatibility-enabled">
features
</a>
that are incompatible with
<!-- -->
4.4
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
To enable these
<!-- -->
5.0
<!-- -->
features, set the feature compatibility
version (
<code class="leafygreen-ui-1l06pbn">
fCV
</code>
) to
<!-- -->
5.0
<!-- -->
.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Enabling these backwards-incompatible features can complicate the
downgrade process since you must remove any persisted backwards-incompatible
features before you downgrade.
</p>
<p class="leafygreen-ui-1kp3ins">
It is recommended that after upgrading, you allow your deployment to run
without enabling these features for a burn-in period to ensure the
likelihood of downgrade is minimal. When you are confident that the
likelihood of downgrade is minimal, enable these features.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
On a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance, run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
command in the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { setFeatureCompatibilityVersion: \"5.0\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">setFeatureCompatibilityVersion</span>: <span class="lg-highlight-string">"5.0"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Setting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-set-fcv">
featureCompatibilityVersion (fCV) : "5.0"
</a>
implicitly performs a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetReconfig/#mongodb-dbcommand-dbcmd.replSetReconfig">
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</a>
on each shard to
add the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.term">
<code class="leafygreen-ui-1l06pbn">
term
</code>
</a>
field to the shard replica configuration
document.
</p>
<p class="leafygreen-ui-1kp3ins">
The command doesn't complete until the new configuration propagates to a
majority of replica set members.
</p>
<p class="leafygreen-ui-1kp3ins">
This command must perform writes to an internal system collection.
If for any reason the command does not complete successfully, you
can safely retry the command on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
as the
operation is idempotent.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
While
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
is running on
the sharded cluster, chunk migrations, splits, and merges
can fail with
<code class="leafygreen-ui-1l06pbn">
ConflictingOperationInProgress
</code>
.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Any
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document">
orphaned documents
</a>
that exist on your
shards will be cleaned up when you set the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
to
<!-- -->
5.0
<!-- -->
. The
cleanup process:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Does not block the upgrade from completing, and
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Is rate limited. To mitigate the potential effect on performance
during orphaned document cleanup, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-range-deletion-performance-tuning">
Range Deletion Performance Tuning
<!-- -->
.
</a>
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Additional Consideration
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
binary cannot connect to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances whose
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
feature compatibility version (fCV)
</a>
is greater
than that of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
. For example, you cannot connect
a MongoDB
<!-- -->
4.4
<!-- -->
version
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
to a
<!-- -->
5.0
<!-- -->
sharded cluster with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
fCV
</a>
set to
<!-- -->
5.0
<!-- -->
. You
can, however, connect a MongoDB
<!-- -->
4.4
<!-- -->
version
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
to a
<!-- -->
5.0
<!-- -->
sharded cluster with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
fCV
</a>
set to
<!-- -->
4.4
<!-- -->
.
</p>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Upgrade Procedures
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-upgrade-procedures" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="additional-upgrade-procedures">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To upgrade a standalone, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0-upgrade-standalone/#std-label-5.0-upgrade-standalone">
Upgrade a Standalone to 5.0
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To upgrade a replica set, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0-upgrade-replica-set/#std-label-5.0-upgrade-replica-set">
Upgrade a Replica Set to 5.0
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/UUID/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
UUID()
<a class="headerlink leafygreen-ui-1kepx47" href="#uuid--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="uuid--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Generates a BSON
<span class="leafygreen-ui-vm4wms" tabindex="0">
UUID
</span>
object.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-UUID" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
UUID()
</code>
</span>
</a>
has the following syntax:
</p>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
UUID(<string>)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-UUID" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-UUID">
</div>
</a>
</dt>
<dd>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Parameter
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
hex
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. Specify a 36 character string to convert to a UUID BSON object. If
not provided, MongoDB generates a random UUID in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4122" rel="noopener noreferrer">
<span>
RFC 4122 v4
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
format.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<table class="css-11h39yh e1nex8bq0">
<colgroup>
<col class="field-name"/>
<col class="field-body"/>
</colgroup>
<tbody>
<tr class="css-x8snli">
<th>
Returns
<!-- -->
:
</th>
<td>
A BSON UUID object.
</td>
</tr>
</tbody>
</table>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Convert Character String to UUID
<a class="headerlink leafygreen-ui-1kepx47" href="#convert-character-string-to-uuid" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="convert-character-string-to-uuid">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create a 36 character string you wish to convert to a UUID:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var myuuid = '3b241101-e2bb-4255-8caf-4136c566a962'","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> myuuid <!-- -->= <span class="lg-highlight-string">'3b241101-e2bb-4255-8caf-4136c566a962'</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following command outputs the
<code class="leafygreen-ui-1l06pbn">
myuuid
</code>
variable as a BSON UUID object:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"UUID(myuuid)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">UUID</span>(<!-- -->myuuid)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This command generates the following output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"UUID(\"3b241101-e2bb-4255-8caf-4136c566a962\")","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"3b241101-e2bb-4255-8caf-4136c566a962"</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Generate Random UUID
<a class="headerlink leafygreen-ui-1kepx47" href="#generate-random-uuid" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="generate-random-uuid">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can run the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-UUID" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
UUID()
</code>
</span>
</a>
method without
specifying an argument to generate a random UUID:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"UUID()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">UUID</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This command outputs a random UUID in the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"UUID(\"dee11d4e-63c6-4d90-983c-5c9f1e79e96c\")","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"dee11d4e-63c6-4d90-983c-5c9f1e79e96c"</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/Bulk.find.update/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Bulk.find.update()
<a class="headerlink leafygreen-ui-1kepx47" href="#bulk.find.update--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="bulk.find.update--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#description" target="_self">
<span>
Description
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
MongoDB also provides the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.bulkWrite/#mongodb-method-db.collection.bulkWrite">
<code class="leafygreen-ui-1l06pbn">
db.collection.bulkWrite()
</code>
</a>
method for
performing bulk write operations.
</p>
</div>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Description
<a class="headerlink leafygreen-ui-1kepx47" href="#description" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="description">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
Bulk.find.update(<update>)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-Bulk.find.update" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-Bulk.find.update">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Adds a
<code class="leafygreen-ui-1l06pbn">
multi
</code>
update operation to a bulk operations list. The
method updates specific fields in existing documents.
</p>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find/#mongodb-method-Bulk.find">
<code class="leafygreen-ui-1l06pbn">
Bulk.find()
</code>
</a>
method to specify the condition that
determines which documents to update. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-Bulk.find.update" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
Bulk.find.update()
</code>
</span>
</a>
method updates all matching documents.
To specify a single document update, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.updateOne/#mongodb-method-Bulk.find.updateOne">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.updateOne()
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-Bulk.find.update" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
Bulk.find.update()
</code>
</span>
</a>
accepts the following parameter:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Parameter
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-bulk-find-update-parameter" target="_self">
<span>
update
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document or pipeline
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-bulk-find-update-parameter">
</span>
<p class="leafygreen-ui-1kp3ins">
The modifications to apply. Can be one of the following:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:40%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Update document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains only
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/#std-label-update-operators">
update operator expressions
<!-- -->
.
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Aggregation pipeline
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Contains only the following aggregation stages:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
<code class="leafygreen-ui-1l06pbn">
$addFields
</code>
</a>
and its alias
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
<code class="leafygreen-ui-1l06pbn">
$project
</code>
</a>
and its alias
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unset/#mongodb-pipeline-pipe.-unset">
<code class="leafygreen-ui-1l06pbn">
$unset
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot">
<code class="leafygreen-ui-1l06pbn">
$replaceRoot
</code>
</a>
and its alias
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith">
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
.
</a>
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on the update modification parameter, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#mongodb-method-db.collection.updateMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateMany()
</code>
</a>
reference page.
</p>
<p class="leafygreen-ui-1kp3ins">
The sum of the associated
<code class="leafygreen-ui-1l06pbn">
<query>
</code>
document from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find/#mongodb-method-Bulk.find">
<code class="leafygreen-ui-1l06pbn">
Bulk.find()
</code>
</a>
and the update document must be less than or
equal to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-BSON-Document-Size">
maximum BSON document size
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To specify an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
upsert: true
</a>
for this operation,
use with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.upsert/#mongodb-method-Bulk.find.upsert">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.upsert()
</code>
</a>
. With
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.upsert/#mongodb-method-Bulk.find.upsert">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.upsert()
</code>
</a>
, if no documents match the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find/#mongodb-method-Bulk.find">
<code class="leafygreen-ui-1l06pbn">
Bulk.find()
</code>
</a>
query condition, the update operation
inserts only a single document.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To specify
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
to update specific array
elements, use with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.arrayFilters/#mongodb-method-Bulk.find.arrayFilters">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.arrayFilters()
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To specify the index to use for the associated
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find/#mongodb-method-Bulk.find">
<code class="leafygreen-ui-1l06pbn">
Bulk.find()
</code>
</a>
, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.hint/#mongodb-method-Bulk.find.hint">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.hint()
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To replace a document wholesale, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.replaceOne/#mongodb-method-Bulk.find.replaceOne">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.replaceOne()
</code>
.
</a>
</p>
</li>
</ul>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following example initializes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk/#mongodb-method-Bulk">
<code class="leafygreen-ui-1l06pbn">
Bulk()
</code>
</a>
operations builder
for the
<code class="leafygreen-ui-1l06pbn">
items
</code>
collection, and adds various
<code class="leafygreen-ui-1l06pbn">
multi
</code>
update
operations to the list of operations.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var bulk = db.items.initializeUnorderedBulkOp();\nbulk.find( { status: \"D\" } ).update( { $set: { status: \"I\", points: \"0\" } } );\nbulk.find( { item: null } ).update( { $set: { item: \"TBD\" } } );\nbulk.execute();","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> bulk <!-- -->= <!-- -->db.<span class="lg-highlight-property">items</span>.<span class="lg-highlight-title lg-highlight-function">initializeUnorderedBulkOp</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">bulk.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"D"</span> } ).<span class="lg-highlight-title lg-highlight-function">update</span>( <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"I"</span>, <span class="lg-highlight-attr">points</span>: <span class="lg-highlight-string">"0"</span> } } )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">bulk.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-literal">null</span> } ).<span class="lg-highlight-title lg-highlight-function">update</span>( <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"TBD"</span> } } )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">bulk.<span class="lg-highlight-title lg-highlight-function">execute</span>(<!-- -->)<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-example-bulk-find-update-agg">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update with Aggregation Pipeline
<a class="headerlink leafygreen-ui-1kepx47" href="#update-with-aggregation-pipeline" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-with-aggregation-pipeline">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Update methods can accept an aggregation pipeline. For
example, the following uses:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
</a>
stage which can provide similar
behavior to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/set/#mongodb-update-up.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
</a>
update operator expression,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the aggregation variable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.NOW">
<code class="leafygreen-ui-1l06pbn">
NOW
</code>
</a>
, which resolves to the
current datetime and can provide similar behavior to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/currentDate/#mongodb-update-up.-currentDate">
<code class="leafygreen-ui-1l06pbn">
$currentDate
</code>
</a>
update operator expression. To access
aggregation variables, prefix the variable with double dollar signs
<code class="leafygreen-ui-1l06pbn">
$$
</code>
and enclose in quotes.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var bulk = db.items.initializeUnorderedBulkOp();\nbulk.find( { status: \"P\" } ).update(\n [\n { $set: { points: 0, lastModified: \"$$NOW\" } }\n ]\n);\nbulk.execute();","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> bulk <!-- -->= <!-- -->db.<span class="lg-highlight-property">items</span>.<span class="lg-highlight-title lg-highlight-function">initializeUnorderedBulkOp</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">bulk.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"P"</span> } ).<span class="lg-highlight-title lg-highlight-function">update</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">points</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">lastModified</span>: <span class="lg-highlight-string">"$$NOW"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">bulk.<span class="lg-highlight-title lg-highlight-function">execute</span>(<!-- -->)<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.initializeUnorderedBulkOp/#mongodb-method-db.collection.initializeUnorderedBulkOp">
<code class="leafygreen-ui-1l06pbn">
db.collection.initializeUnorderedBulkOp()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.initializeOrderedBulkOp/#mongodb-method-db.collection.initializeOrderedBulkOp">
<code class="leafygreen-ui-1l06pbn">
db.collection.initializeOrderedBulkOp()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find/#mongodb-method-Bulk.find">
<code class="leafygreen-ui-1l06pbn">
Bulk.find()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.updateOne/#mongodb-method-Bulk.find.updateOne">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.updateOne()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.execute/#mongodb-method-Bulk.execute">
<code class="leafygreen-ui-1l06pbn">
Bulk.execute()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk/#std-label-bulk-methods">
All Bulk Methods
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/csfle/tutorials/kmip/kmip-automatic/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Use Automatic Client-Side Field Level Encryption with KMIP
<a class="headerlink leafygreen-ui-1kepx47" href="#use-automatic-client-side-field-level-encryption-with-kmip" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-automatic-client-side-field-level-encryption-with-kmip">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#before-you-get-started" target="_self">
<span>
Before You Get Started
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#full-application-code" target="_self">
<span>
Full Application Code
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#set-up-the-kms" target="_self">
<span>
Set Up the KMS
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#configure-your-kmip-compliant-key-provider" target="_self">
<span>
Configure your KMIP-compliant key provider
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#specify-your-certificates" target="_self">
<span>
Specify your Certificates
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#create-the-application" target="_self">
<span>
Create the Application
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-a-unique-index-on-your-key-vault-collection" target="_self">
<span>
Create a Unique Index on Your Key Vault Collection
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-a-data-encryption-key" target="_self">
<span>
Create a Data Encryption Key
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#configure-the-mongoclient" target="_self">
<span>
Configure the MongoClient
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#insert-a-document-with-encrypted-fields" target="_self">
<span>
Insert a Document with Encrypted Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#retrieve-your-document-with-encrypted-fields" target="_self">
<span>
Retrieve Your Document with Encrypted Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This guide shows you how to build a Client-Side Field Level Encryption (CSFLE)-enabled
application using a Key Management Interoperability Protocol
(KMIP)-compliant key provider.
</p>
<p class="leafygreen-ui-1kp3ins">
After you complete the steps in this guide, you should have:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A Customer Master Key hosted on a
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A working client application that inserts documents with encrypted fields
using your Customer Master Key.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Before You Get Started
<a class="headerlink leafygreen-ui-1kepx47" href="#before-you-get-started" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="before-you-get-started">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To complete and run the code in this guide, you need to set up your
development environment as shown in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/install/#std-label-csfle-install">
Installation Requirements
</a>
page.
</p>
<p class="leafygreen-ui-1kp3ins">
Throughout this guide, code examples use placeholder text.
Before you run the examples, substitute your own values for
these placeholders.
</p>
<p class="leafygreen-ui-1kp3ins">
For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dek_id := \"<your>\"","programmingLanguage":"Golang"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light go leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">dek_id <!-- -->:=<!-- --> <span class="lg-highlight-string">"<Your Base64 DEK ID>"</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You would replace everything between quotes with your
<span class="leafygreen-ui-vm4wms" tabindex="0">
DEK
</span>
ID.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dek_id := \"abc123\"","programmingLanguage":"Golang"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light go leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">dek_id <!-- -->:=<!-- --> <span class="lg-highlight-string">"abc123"</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Select the programming language for which you want to see code examples for
from the
<span class="guilabel css-h15tq0">
Select your language
</span>
dropdown menu on the right side of
the page.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Full Application Code
<a class="headerlink leafygreen-ui-1kepx47" href="#full-application-code" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="full-application-code">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To see the complete code for the sample application, select your programming
language in the language selector.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-7">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_h0zrvo3ai" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_1t38ceszl" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_dro0ax7en" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_g85use0hf" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_75vb627pf" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_nskugbsc6" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_carhlq8gx" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_u7zvkcsu5" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_far99iz39" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xxn984x6n" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_xyxtyz3fu" class="leafygreen-ui-38lglc" id="_lt3tyjw4k" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/kmip/reader/CSFLE/" rel="noopener noreferrer">
<span>
Complete C# Application
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_kidroojff" class="leafygreen-ui-38lglc" id="_cpyjum68z" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/kmip/reader/" rel="noopener noreferrer">
<span>
Complete Go Application
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_lkny2gcr5" class="leafygreen-ui-38lglc" id="_l96rd3vxa" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/kmip/reader/" rel="noopener noreferrer">
<span>
Complete Java Application
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_iisrsd7cd" class="" id="_y4rr6gg62" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/kmip/reader/" rel="noopener noreferrer">
<span>
Complete Node.js Application
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_rs0jq3r4y" class="leafygreen-ui-38lglc" id="_4zmymxpe8" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/kmip/reader/" rel="noopener noreferrer">
<span>
Complete Python Application
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Set Up the KMS
<a class="headerlink leafygreen-ui-1kepx47" href="#set-up-the-kms" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="set-up-the-kms">
</div>
</a>
</h2>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
reads the KMIP configuration at startup. By default, the
server uses KMIP protocol version 1.2.
</p>
<p class="leafygreen-ui-1kp3ins">
To connect to a version 1.0 or 1.1 KMIP server, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.kmip.useLegacyProtocol">
<code class="leafygreen-ui-1l06pbn">
useLegacyProtocol
</code>
</a>
setting.
</p>
</div>
</div>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-9">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_ese40yu42" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_gwreryibl" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_kvj8ugcbl" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_aiw4uo004" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_8yjeezuqu" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_krhfqtpsm" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_vlkuagb0j" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_duge5hlk8" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_idm8ktw8d" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_qcjak5y2i" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_bys7dhuf1" class="leafygreen-ui-38lglc" id="_n9qj1h33q" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// You are viewing the C# driver code examples.\n// Use the dropdown menu to select a different driver.","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> You are viewing </span><span class="lg-highlight-comment">the C# driver code examples.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Use the dropdown </span><span class="lg-highlight-comment">menu</span><span class="lg-highlight-comment"> to select a </span><span class="lg-highlight-comment">different driver.</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-44-menu" aria-describedby="select-44-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-45" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8k:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8k:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8k:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8k:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_e65mkz6jp" class="leafygreen-ui-38lglc" id="_4lwh5i97l" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// You are viewing the Golang driver code examples.\n// Use the dropdown menu to select a different driver.","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> You are viewing </span><span class="lg-highlight-comment">the</span><span class="lg-highlight-comment"> Golang driver code </span><span class="lg-highlight-comment">examples.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Use the dropdown </span><span class="lg-highlight-comment">menu</span><span class="lg-highlight-comment"> to select a </span><span class="lg-highlight-comment">different driver.</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-47-menu" aria-describedby="select-47-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-48" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8l:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8l:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8l:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8l:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
When building or running the Golang code in this guide using
<code class="leafygreen-ui-1l06pbn">
go build
</code>
or
<code class="leafygreen-ui-1l06pbn">
go run
</code>
, always include the
<code class="leafygreen-ui-1l06pbn">
cse
</code>
build
constraint to enable CSFLE. See the following shell
command for an example of including the build constraint:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"go run -tags cse insert-encrypted-document.go","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">go run -tags cse insert-encrypted-<span class="lg-highlight-variable lg-highlight-language">document</span>.<span class="lg-highlight-property">go</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-50-menu" aria-describedby="select-50-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-51" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8m:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8m:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8m:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8m:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ujf18cmcn" class="leafygreen-ui-38lglc" id="_lzg9phkyt" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// You are viewing the Java synchronous driver code examples.\n// Use the dropdown menu to select a different driver.","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> You are viewing </span><span class="lg-highlight-comment">the</span><span class="lg-highlight-comment"> Java synchronous driver </span><span class="lg-highlight-comment">code examples.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Use the dropdown </span><span class="lg-highlight-comment">menu</span><span class="lg-highlight-comment"> to select a </span><span class="lg-highlight-comment">different driver.</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-53-menu" aria-describedby="select-53-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-54" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8n:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8n:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8n:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8n:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_20i1pu3fa" class="" id="_3vr27jk19" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// You are viewing the Node.js driver code examples.\n// Use the dropdown menu to select a different driver.","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> You are viewing </span><span class="lg-highlight-comment">the Node.js driver code examples.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Use the dropdown </span><span class="lg-highlight-comment">menu</span><span class="lg-highlight-comment"> to select a </span><span class="lg-highlight-comment">different driver.</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-56-menu" aria-describedby="select-56-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-57" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8o:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8o:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8o:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8o:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ggoyvtkhk" class="leafygreen-ui-38lglc" id="_twxd8mscy" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"# You are viewing the Python driver code examples.\n# Use the dropdown menu to select a different driver.","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-title lg-highlight-class">You</span> are viewing the <span class="lg-highlight-title lg-highlight-class">Python</span> driver code examples.</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-title lg-highlight-class">Use</span> the dropdown menu to select a different driver.</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-59-menu" aria-describedby="select-59-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-60" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8p:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8p:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8p:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8p:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"To connect a MongoDB driver client to your KMIP (Key Management Interoperability Protocol)-compliant key provider, you must configure\nyour KMIP (Key Management Interoperability Protocol)-compliant key provider such that it accepts your client's TLS certificate.Consult the documentation for your KMIP (Key Management Interoperability Protocol)-compliant key provider for\ninformation on how to accept your client certificate.","name":"Configure your KMIP-compliant key provider"},{"@type":"HowToStep","text":"Your client must connect to your KMIP (Key Management Interoperability Protocol)-compliant key provider through TLS and present\na client certificate that your KMIP (Key Management Interoperability Protocol)-compliant key provider accepts:Your client certificate must be in pkcs12 format. You can convert\nyour certificate using your certificate using OpenSSL\nwith the following command:You must use certificates with ECDSA keys\nwhen using the Go driver.Specify the following Java system properties to configure your client's\nTLS connection:If you would rather configure your client application using an SSL context, use the\nkmsProviderSslContextMap\nmethod.","name":"Specify your Certificates"}],"name":"Set Up the KMS","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Configure your KMIP-compliant key provider
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-your-kmip-compliant-key-provider" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configure-your-kmip-compliant-key-provider">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To connect a MongoDB driver client to your
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider, you must configure
your
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider such that it accepts your client's TLS certificate.
</p>
<p class="leafygreen-ui-1kp3ins">
Consult the documentation for your
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider for
information on how to accept your client certificate.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Specify your Certificates
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-your-certificates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="specify-your-certificates">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Your client must connect to your
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider through TLS and present
a client certificate that your
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider accepts:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-12">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_1e31ix9t9" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_55xqrv0g3" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_e4pjdy5ck" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_vp2aje9nw" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_7hq6jcilv" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_b9vx0gz06" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_iwb9lmx6w" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_nvp5nyc90" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_szxwnnpkl" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_oxacg3oel" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_2ikoaa2gu" class="leafygreen-ui-38lglc" id="_c16yvdyqo" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var tlsOptions = new Dictionary<string,>();\nvar sslSettings = new SslSettings();\nvar clientCertificate = new X509Certificate2(\"<path>\");\nsslSettings.ClientCertificates = new List<x509certificate>() {\n clientCertificate,\n };\ntlsOptions.Add(provider, sslSettings);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> tlsOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span><string, <span class="lg-highlight-title lg-highlight-class">SslSettings</span>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> sslSettings = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">SslSettings</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> clientCertificate = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-function">X509Certificate2</span>(<span class="lg-highlight-string">"<path to your pkcs12 client certificate file>"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sslSettings.<span class="lg-highlight-property">ClientCertificates</span> = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">List</span><X509Certificate>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> clientCertificate,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> };</td></tr><tr class=""><td class="leafygreen-ui-7razhx">tlsOptions.<span class="lg-highlight-title lg-highlight-class">Add</span>(provider, sslSettings);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-62-menu" aria-describedby="select-62-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-63" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8q:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8q:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8q:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8q:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Your client certificate must be in pkcs12 format. You can convert
your certificate using your certificate using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.openssl.org/master/" rel="noopener noreferrer">
<span>
OpenSSL
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
with the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"openssl pkcs12 -export -out \"<new>\" -in \"<certificate>\" \\\n-name \"<new>\" -password \"<new>\"","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">openssl pkcs12 -<span class="lg-highlight-keyword">export</span> -out <span class="lg-highlight-string">"<new pkcs12 certificate>"</span> -<span class="lg-highlight-keyword">in</span> <span class="lg-highlight-string">"<certificate to convert>"</span> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">-name <span class="lg-highlight-string">"<new certificate name>"</span> -password <span class="lg-highlight-string">"<new certificate password>"</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-65-menu" aria-describedby="select-65-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-66" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8r:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8r:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8r:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8r:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_o7ij6122h" class="leafygreen-ui-38lglc" id="_c47er52sg" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"tlsConfig := make(map[string]*tls.Config)\ntlsOpts := map[string]interface{}{\n\t\"tlsCertificateKeyFile\": \"<path>\",\n\t\"tlsCAFile\": \"<path>\",\n}\nkmipConfig, err := options.BuildTLSConfig(tlsOpts)\ntlsConfig[\"kmip\"] = kmipConfig","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">tlsConfig <!-- -->:<!-- -->= <span class="lg-highlight-title lg-highlight-function">make</span>(map[string]*tls.<span class="lg-highlight-property">Config</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">tlsOpts <!-- -->:<!-- -->= map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tlsCertificateKeyFile"</span>: <span class="lg-highlight-string">"<path to your client certificate file>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tlsCAFile"</span>: <span class="lg-highlight-string">"<path to file containing your Certificate Authority certificate>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmipConfig<!-- -->, <!-- -->err := options.<span class="lg-highlight-title lg-highlight-class">BuildTLSConfig</span>(tlsOpts)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">tlsConfig[<span class="lg-highlight-string">"kmip"</span>] = kmipConfig</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-68-menu" aria-describedby="select-68-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-69" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8s:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8s:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8s:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8s:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
You must use certificates with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm" rel="noopener noreferrer">
<span>
ECDSA keys
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
when using the Go driver.
</p>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_1alm23qhk" class="leafygreen-ui-38lglc" id="_hgnbt8rf3" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
Specify the following Java system properties to configure your client's
TLS connection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"-Djavax.net.ssl.keyStoreType=pkcs12\n-Djavax.net.ssl.keyStore=<path>\n-Djavax.net.ssl.keyStorePassword=<keystore>","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">-<span class="lg-highlight-title lg-highlight-class">Djavax</span>.<span class="lg-highlight-property">net</span>.<span class="lg-highlight-property">ssl</span>.<span class="lg-highlight-property">keyStoreType</span>=pkcs12</td></tr><tr class=""><td class="leafygreen-ui-7razhx">-<span class="lg-highlight-title lg-highlight-class">Djavax</span>.<span class="lg-highlight-property">net</span>.<span class="lg-highlight-property">ssl</span>.<span class="lg-highlight-property">keyStore</span>=<path to pkcs12 KeyStore containing your client certificate></td></tr><tr class=""><td class="leafygreen-ui-7razhx">-Djavax.net.ssl.keyStorePassword=<KeyStore password></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-71-menu" aria-describedby="select-71-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-72" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8t:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8t:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8t:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8t:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Configure Client With SSLContext
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If you would rather configure your client application using an SSL context, use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://mongodb.github.io/mongo-java-driver/4.6/apidocs/mongodb-driver-core/com/mongodb/ClientEncryptionSettings.Builder.html#kmsProviderSslContextMap(java.util.Map)" rel="noopener noreferrer">
<span>
kmsProviderSslContextMap
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
method.
</p>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_0vkh9tbcf" class="" id="_rybf5b3g9" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const tlsOptions = {\n kmip: {\n tlsCAFile:\n \"<path>\",\n tlsCertificateKeyFile: \"<path>\",\n },\n};","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> tlsOptions <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmip</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tlsCAFile</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<path to file containing your Certificate Authority certificate>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tlsCertificateKeyFile</span>: <span class="lg-highlight-string">"<path to your client certificate file>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-74-menu" aria-describedby="select-74-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-75" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8u:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8u:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8u:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8u:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_lwmr2ycfr" class="leafygreen-ui-38lglc" id="_li4v028ac" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"tls_options = {\n \"kmip\": {\n \"tlsCAFile\": \"<path>\",\n \"tlsCertificateKeyFile\": \"<path>\",\n }\n}","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">tls_options = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"kmip"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tlsCAFile"</span>: <span class="lg-highlight-string">"<path to file containing your Certificate Authority certificate>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tlsCertificateKeyFile"</span>: <span class="lg-highlight-string">"<path to your client certificate file>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-77-menu" aria-describedby="select-77-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-78" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r8v:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r8v:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8v:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r8v:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Create the Application
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-application" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-the-application">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Select the tab that corresponds to the MongoDB driver you are using in
your application to see relevant code samples.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create a unique index on the keyAltNames field in your\nencryption.__keyVault namespace.Select the tab corresponding to your preferred MongoDB driver:","name":"Create a Unique Index on Your Key Vault Collection"},{"@type":"HowToStep","text":"Add your EndpointSpecify the URI endpoint of your KMIP (Key Management Interoperability Protocol)-compliant key provider:Add Your Key InformationThe following code prompts your KMIP (Key Management Interoperability Protocol)-compliant key provider to automatically generate a Customer Master Key:Generate your Data Encryption KeyGenerate your Data Encryption Key using the variables declared in step one of this tutorial.When using the Node.js driver v6.0 and later, you must import\nClientEncryption from mongodb.For earlier driver versions, import ClientEncryption from\nmongodb-client-encryption.To view the complete code for making a Data Encryption Key, see\nour Github repository.To view the complete code for making a Data Encryption Key, see\nour Github repository.To view the complete code for making a Data Encryption Key, see\nour Github repository.To view the complete code for making a Data Encryption Key, see\nour Github repository.To view the complete code for making a Data Encryption Key, see\nour Github repository.","name":"Create a Data Encryption Key"},{"@type":"HowToStep","text":"Follow the remaining steps in this tutorial in a separate file\nfrom the one created in the previous steps.To view the complete code for this file, see\nour Github repositoryTo view the complete code for this file, see\nour Github repository.To view the complete code for this file, see\nour Github repository.To view the complete code for this file, see\nour Github repository.To view the complete code for this file, see\nour Github repository.Specify the Key Vault Collection NamespaceSpecify encryption.__keyVault as the Key Vault collection\nnamespace.Specify your KMIP EndpointSpecify kmip in your kmsProviders object and enter\nthe URI endpoint of your KMIP (Key Management Interoperability Protocol)-compliant key provider:Create an Encryption Schema For Your CollectionCreate an encryption schema that specifies how your client\napplication encrypts your documents' fields:Make sure to update the following code to include your Base64\nDEK (Data Encryption Key) ID. You received this value in the\nGenerate your Data Encryption Key step of this\nguide.To view an in-depth description of how to construct the schema you use\nin this step, see the Encryption Schemas guide.To view a list of all supported encryption rules for your\nencryption schemas, see the\nCSFLE Encryption Schemas guide.Specify the Location of the Automatic Encryption Shared LibraryThe automatic encryption options provide configuration\ninformation to the Automatic Encryption Shared Library,\nwhich modifies the application's behavior when accessing encrypted fields.To learn more about the Automatic Encryption Shared Library, see\nthe Install and Configure a CSFLE Library page.Create the MongoClientInstantiate a MongoDB client object with the following automatic\nencryption settings that use the variables declared in the previous steps:","name":"Configure the MongoClient"},{"@type":"HowToStep","text":"Use your CSFLE-enabled\nMongoClient instance to insert a document with encrypted fields into the\nmedicalRecords.patients namespace using the following code\nsnippet:Rather than creating a raw BSON document, you can pass a struct with bson tags directly\nto the driver for encoding.When you insert a document, your CSFLE-enabled client\nencrypts the fields of your document such that it resembles the following:To view the complete code for inserting a document with encrypted fields, see\nour Github repositoryTo view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.","name":"Insert a Document with Encrypted Fields"},{"@type":"HowToStep","text":"Retrieve the document with encrypted fields you inserted in the\nInsert a Document with Encrypted Fields\nstep of this guide.To show the functionality of CSFLE, the following code snippet queries for\nyour document with a client configured for automatic CSFLE as well as\na client that is not configured for automatic CSFLE.The output of the preceding code snippet should look like this:To view the complete code for inserting a document with encrypted fields, see\nour Github repositoryTo view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.To view the complete code for inserting a document with encrypted fields, see\nour Github repository.","name":"Retrieve Your Document with Encrypted Fields"}],"name":"Create the Application","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create a Unique Index on Your Key Vault Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-unique-index-on-your-key-vault-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-a-unique-index-on-your-key-vault-collection">
</div>
</a>
</h3>
<span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-kmip-create-index">
</span>
<p class="leafygreen-ui-1kp3ins">
Create a unique index on the
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
field in your
<code class="leafygreen-ui-1l06pbn">
encryption.__keyVault
</code>
namespace.
</p>
<p class="leafygreen-ui-1kp3ins">
Select the tab corresponding to your preferred MongoDB driver:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-15">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_0t1twefrd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_7nrps5pvu" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_b0es8x6s5" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_tjvj70tir" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_y55k18qr1" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_q0f92hznw" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_3o3wfpzbs" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_i45117zve" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_kdxj3oiva" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_tfzv0baww" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_h7lepv0y0" class="leafygreen-ui-38lglc" id="_5km54xjb4" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var connectionString = \"<your>\";\nvar keyVaultNamespace = CollectionNamespace.FromFullName(\"encryption.__keyVault\");\nvar keyVaultClient = new MongoClient(connectionString);\nvar indexOptions = new CreateIndexOptions<bsondocument>();\nindexOptions.Unique = true;\nindexOptions.PartialFilterExpression = new BsonDocument { { \"keyAltNames\", new BsonDocument { { \"$exists\", new BsonBoolean(true) } } } };\nvar builder = Builders<bsondocument>.IndexKeys;\nvar indexKeysDocument = builder.Ascending(\"keyAltNames\");\nvar indexModel = new CreateIndexModel<bsondocument>(indexKeysDocument, indexOptions);\nvar keyVaultDatabase = keyVaultClient.GetDatabase(keyVaultNamespace.DatabaseNamespace.ToString());\n// Drop the Key Vault Collection in case you created this collection\n// in a previous run of this application. \nkeyVaultDatabase.DropCollection(keyVaultNamespace.CollectionName);\n// Drop the database storing your encrypted fields as all\n// the DEKs encrypting those fields were deleted in the preceding line.\nkeyVaultClient.GetDatabase(\"medicalRecords\").DropCollection(\"patients\");\nvar keyVaultCollection = keyVaultDatabase.GetCollection<bsondocument>(keyVaultNamespace.CollectionName.ToString());\nkeyVaultCollection.Indexes.CreateOne(indexModel);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> connectionString = <span class="lg-highlight-string">"<Your MongoDB URI>"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultNamespace = <span class="lg-highlight-title lg-highlight-class">CollectionNamespace</span>.<span class="lg-highlight-title lg-highlight-class">FromFullName</span>(<span class="lg-highlight-string">"encryption.__keyVault"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultClient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connectionString);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> indexOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">CreateIndexOptions</span><<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">indexOptions.<span class="lg-highlight-property">Unique</span> = <span class="lg-highlight-literal">true</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">indexOptions.<span class="lg-highlight-property">PartialFilterExpression</span> = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span> { { <span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span> { { <span class="lg-highlight-string">"$exists"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonBoolean</span>(<span class="lg-highlight-literal">true</span>) } } } };</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> builder = <span class="lg-highlight-title lg-highlight-class">Builders</span><<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>.<span class="lg-highlight-property">IndexKeys</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> indexKeysDocument = builder.<span class="lg-highlight-title lg-highlight-class">Ascending</span>(<span class="lg-highlight-string">"keyAltNames"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> indexModel = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">CreateIndexModel</span><<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>(indexKeysDocument, indexOptions);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultDatabase = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">GetDatabase</span>(keyVaultNamespace.<span class="lg-highlight-property">DatabaseNamespace</span>.<span class="lg-highlight-title lg-highlight-class">ToString</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the Key </span><span class="lg-highlight-comment">Vault</span><span class="lg-highlight-comment"> Collection in case </span><span class="lg-highlight-comment">you created this collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> in a previous </span><span class="lg-highlight-comment">run of this application. </span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultDatabase.<span class="lg-highlight-title lg-highlight-class">DropCollection</span>(keyVaultNamespace.<span class="lg-highlight-property">CollectionName</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the database </span><span class="lg-highlight-comment">storing</span><span class="lg-highlight-comment"> your encrypted fields </span><span class="lg-highlight-comment">as all</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// the DEKs</span><span class="lg-highlight-comment"> encrypting those fields </span><span class="lg-highlight-comment">were</span><span class="lg-highlight-comment"> deleted in the </span><span class="lg-highlight-comment">preceding line.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient.<span class="lg-highlight-title lg-highlight-class">GetDatabase</span>(<span class="lg-highlight-string">"medicalRecords"</span>).<span class="lg-highlight-title lg-highlight-class">DropCollection</span>(<span class="lg-highlight-string">"patients"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultCollection = keyVaultDatabase.<span class="lg-highlight-property">GetCollection</span><<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>(keyVaultNamespace.<span class="lg-highlight-property">CollectionName</span>.<span class="lg-highlight-title lg-highlight-class">ToString</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultCollection.<span class="lg-highlight-property">Indexes</span>.<span class="lg-highlight-title lg-highlight-class">CreateOne</span>(indexModel);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-80-menu" aria-describedby="select-80-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-81" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r90:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r90:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r90:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r90:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_i8qv0yj0a" class="leafygreen-ui-38lglc" id="_k4by9sac2" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"uri := \"<your>\"\nkeyVaultClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))\nif err != nil {\n\treturn fmt.Errorf(\"Connect error for regular client: %v\", err)\n}\ndefer func() {\n\t_ = keyVaultClient.Disconnect(context.TODO())\n}()\n\nkeyVaultColl := \"__keyVault\"\nkeyVaultDb := \"encryption\"\nkeyVaultNamespace := keyVaultDb + \".\" + keyVaultColl\nkeyVaultIndex := mongo.IndexModel{\n\tKeys: bson.D{{\"keyAltNames\", 1}},\n\tOptions: options.Index().\n\t\tSetUnique(true).\n\t\tSetPartialFilterExpression(bson.D{\n\t\t\t{\"keyAltNames\", bson.D{\n\t\t\t\t{\"$exists\", true},\n\t\t\t}},\n\t\t}),\n}\n// Drop the Key Vault Collection in case you created this collection\n// in a previous run of this application.\nif err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Drop(context.TODO()); err != nil {\n\tlog.Fatalf(\"Collection.Drop error: %v\", err)\n}\n// Drop the database storing your encrypted fields as all\n// the DEKs encrypting those fields were deleted in the preceding line.\nif err = keyVaultClient.Database(\"medicalRecords\").Collection(\"patients\").Drop(context.TODO()); err != nil {\n\tlog.Fatalf(\"Collection.Drop error: %v\", err)\n}\n_, err = keyVaultClient.Database(keyVaultDb).Collection(keyVaultColl).Indexes().CreateOne(context.TODO(), keyVaultIndex)\nif err != nil {\n\tpanic(err)\n}","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">uri <!-- -->:<!-- -->= <span class="lg-highlight-string">"<Your MongoDB URI>"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">Connect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), options.<span class="lg-highlight-title lg-highlight-class">Client</span>().<span class="lg-highlight-title lg-highlight-class">ApplyURI</span>(uri))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"Connect error for regular client: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">defer <span class="lg-highlight-title lg-highlight-function">func</span>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _ = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">Disconnect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultColl <!-- -->:<!-- -->= <span class="lg-highlight-string">"__keyVault"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultDb <!-- -->:<!-- -->= <span class="lg-highlight-string">"encryption"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultNamespace <!-- -->:<!-- -->= keyVaultDb + <span class="lg-highlight-string">"."</span> + keyVaultColl</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultIndex <!-- -->:<!-- -->= mongo.<span class="lg-highlight-property">IndexModel</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Keys</span>: bson.<span class="lg-highlight-property">D</span>{{<span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-number">1</span>}},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Options</span>: options.<span class="lg-highlight-title lg-highlight-class">Index</span>().</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetUnique</span>(<span class="lg-highlight-literal">true</span>).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetPartialFilterExpression</span>(bson.<span class="lg-highlight-property">D</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {<span class="lg-highlight-string">"keyAltNames"</span>, bson.<span class="lg-highlight-property">D</span>{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {<span class="lg-highlight-string">"$exists"</span>, <span class="lg-highlight-literal">true</span>},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }),</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the Key </span><span class="lg-highlight-comment">Vault</span><span class="lg-highlight-comment"> Collection in case </span><span class="lg-highlight-comment">you created this collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> in a previous </span><span class="lg-highlight-comment">run of this application.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(keyVaultDb).<span class="lg-highlight-title lg-highlight-class">Collection</span>(keyVaultColl).<span class="lg-highlight-title lg-highlight-class">Drop</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>()); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> log.<span class="lg-highlight-title lg-highlight-class">Fatalf</span>(<span class="lg-highlight-string">"Collection.Drop error: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the database </span><span class="lg-highlight-comment">storing</span><span class="lg-highlight-comment"> your encrypted fields </span><span class="lg-highlight-comment">as all</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// the DEKs</span><span class="lg-highlight-comment"> encrypting those fields </span><span class="lg-highlight-comment">were</span><span class="lg-highlight-comment"> deleted in the </span><span class="lg-highlight-comment">preceding line.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(<span class="lg-highlight-string">"medicalRecords"</span>).<span class="lg-highlight-title lg-highlight-class">Collection</span>(<span class="lg-highlight-string">"patients"</span>).<span class="lg-highlight-title lg-highlight-class">Drop</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>()); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> log.<span class="lg-highlight-title lg-highlight-class">Fatalf</span>(<span class="lg-highlight-string">"Collection.Drop error: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">_, err = keyVaultClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(keyVaultDb).<span class="lg-highlight-title lg-highlight-class">Collection</span>(keyVaultColl).<span class="lg-highlight-title lg-highlight-class">Indexes</span>().<span class="lg-highlight-title lg-highlight-class">CreateOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), keyVaultIndex)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-83-menu" aria-describedby="select-83-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-84" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r91:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r91:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r91:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r91:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_wtkey0gn0" class="leafygreen-ui-38lglc" id="_d0zh4binh" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String connectionString = \"<your>\";\nString keyVaultDb = \"encryption\";\nString keyVaultColl = \"__keyVault\";\nString keyVaultNamespace = keyVaultDb + \".\" + keyVaultColl;\nMongoClient keyVaultClient = MongoClients.create(connectionString);\n\n// Drop the Key Vault Collection in case you created this collection\n// in a previous run of this application.\nkeyVaultClient.getDatabase(keyVaultDb).getCollection(keyVaultColl).drop();\n// Drop the database storing your encrypted fields as all\n// the DEKs encrypting those fields were deleted in the preceding line.\nkeyVaultClient.getDatabase(\"medicalRecords\").getCollection(\"patients\").drop();\n\n\nMongoCollection keyVaultCollection = keyVaultClient.getDatabase(keyVaultDb).getCollection(keyVaultColl);\nIndexOptions indexOpts = new IndexOptions().partialFilterExpression(new BsonDocument(\"keyAltNames\", new BsonDocument(\"$exists\", new BsonBoolean(true) ))).unique(true);\nkeyVaultCollection.createIndex(new BsonDocument(\"keyAltNames\", new BsonInt32(1)), indexOpts);\nkeyVaultClient.close();","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> connectionString = <span class="lg-highlight-string">"<Your MongoDB URI>"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultDb = <span class="lg-highlight-string">"encryption"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultColl = <span class="lg-highlight-string">"__keyVault"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultNamespace = keyVaultDb + <span class="lg-highlight-string">"."</span> + keyVaultColl;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoClient</span> keyVaultClient = <span class="lg-highlight-title lg-highlight-class">MongoClients</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(connectionString);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the Key </span><span class="lg-highlight-comment">Vault</span><span class="lg-highlight-comment"> Collection in case </span><span class="lg-highlight-comment">you created this collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> in a previous </span><span class="lg-highlight-comment">run of this application.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(keyVaultDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(keyVaultColl).<span class="lg-highlight-title lg-highlight-function">drop</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the database </span><span class="lg-highlight-comment">storing</span><span class="lg-highlight-comment"> your encrypted fields </span><span class="lg-highlight-comment">as all</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// the DEKs</span><span class="lg-highlight-comment"> encrypting those fields </span><span class="lg-highlight-comment">were</span><span class="lg-highlight-comment"> deleted in the </span><span class="lg-highlight-comment">preceding line.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(<span class="lg-highlight-string">"medicalRecords"</span>).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(<span class="lg-highlight-string">"patients"</span>).<span class="lg-highlight-title lg-highlight-function">drop</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoCollection</span> keyVaultCollection = keyVaultClient.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(keyVaultDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(keyVaultColl);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">IndexOptions</span> indexOpts = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">IndexOptions</span>().<span class="lg-highlight-title lg-highlight-function">partialFilterExpression</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"$exists"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonBoolean</span>(<span class="lg-highlight-literal">true</span>) ))).<span class="lg-highlight-title lg-highlight-function">unique</span>(<span class="lg-highlight-literal">true</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultCollection.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonInt32</span>(<span class="lg-highlight-number">1</span>)), indexOpts);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVaultClient.<span class="lg-highlight-title lg-highlight-function">close</span>();</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-86-menu" aria-describedby="select-86-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-87" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r92:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r92:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r92:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r92:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_h4hrrcgws" class="" id="_0v1bj84b2" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const uri = \"<your>\";\nconst keyVaultDatabase = \"encryption\";\nconst keyVaultCollection = \"__keyVault\";\nconst keyVaultNamespace = `${keyVaultDatabase}.${keyVaultCollection}`;\nconst keyVaultClient = new MongoClient(uri);\nawait keyVaultClient.connect();\nconst keyVaultDB = keyVaultClient.db(keyVaultDatabase);\n// Drop the Key Vault Collection in case you created this collection\n// in a previous run of this application.\nawait keyVaultDB.dropDatabase();\n// Drop the database storing your encrypted fields as all\n// the DEKs encrypting those fields were deleted in the preceding line.\nawait keyVaultClient.db(\"medicalRecords\").dropDatabase();\nconst keyVaultColl = keyVaultDB.collection(keyVaultCollection);\nawait keyVaultColl.createIndex(\n { keyAltNames: 1 },\n {\n unique: true,\n partialFilterExpression: { keyAltNames: { $exists: true } },\n }\n);","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> uri <!-- -->= <span class="lg-highlight-string">"<Your Connection String>"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultDatabase <!-- -->= <span class="lg-highlight-string">"encryption"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultCollection <!-- -->= <span class="lg-highlight-string">"__keyVault"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultNamespace <!-- -->= <span class="lg-highlight-string">`</span><span class="lg-highlight-subst lg-highlight-string">${keyVaultDatabase}</span><span class="lg-highlight-string">.</span><span class="lg-highlight-subst lg-highlight-string">${keyVaultCollection}</span><span class="lg-highlight-string">`</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultClient <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(<!-- -->uri)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultClient.<span class="lg-highlight-title lg-highlight-function">connect</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultDB <!-- -->= <!-- -->keyVaultClient.<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->keyVaultDatabase)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the Key </span><span class="lg-highlight-comment">Vault</span><span class="lg-highlight-comment"> Collection in case </span><span class="lg-highlight-comment">you created this collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> in a previous </span><span class="lg-highlight-comment">run of this application.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultDB.<span class="lg-highlight-title lg-highlight-function">dropDatabase</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Drop the database </span><span class="lg-highlight-comment">storing</span><span class="lg-highlight-comment"> your encrypted fields </span><span class="lg-highlight-comment">as all</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// the DEKs</span><span class="lg-highlight-comment"> encrypting those fields </span><span class="lg-highlight-comment">were</span><span class="lg-highlight-comment"> deleted in the </span><span class="lg-highlight-comment">preceding line.</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultClient.<span class="lg-highlight-title lg-highlight-function">db</span>(<span class="lg-highlight-string">"medicalRecords"</span>).<span class="lg-highlight-title lg-highlight-function">dropDatabase</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultColl <!-- -->= <!-- -->keyVaultDB.<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->keyVaultCollection)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultColl.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">keyAltNames</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">partialFilterExpression</span>: <!-- -->{ <span class="lg-highlight-attr">keyAltNames</span>: <!-- -->{ <span class="lg-highlight-attr">$exists</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-89-menu" aria-describedby="select-89-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-90" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r93:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r93:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r93:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r93:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_a54f68csn" class="leafygreen-ui-38lglc" id="_isucxocpt" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"connection_string = \"<your>\"\n\nkey_vault_coll = \"__keyVault\"\nkey_vault_db = \"encryption\"\nkey_vault_namespace = f\"{key_vault_db}.{key_vault_coll}\"\nkey_vault_client = MongoClient(connection_string)\n# Drop the Key Vault Collection in case you created this collection\n# in a previous run of this application.\nkey_vault_client.drop_database(key_vault_db)\n# Drop the database storing your encrypted fields as all\n# the DEKs encrypting those fields were deleted in the preceding line.\nkey_vault_client[\"medicalRecords\"].drop_collection(\"patients\")\nkey_vault_client[key_vault_db][key_vault_coll].create_index(\n [(\"keyAltNames\", ASCENDING)],\n unique=True,\n partialFilterExpression={\"keyAltNames\": {\"$exists\": True}},\n)","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">connection_string = <span class="lg-highlight-string">"<your connection string here>"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_coll = <span class="lg-highlight-string">"__keyVault"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_db = <span class="lg-highlight-string">"encryption"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_namespace = f<span class="lg-highlight-string">"{key_vault_db}.{key_vault_coll}"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_client = <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connection_string)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-title lg-highlight-class">Drop</span> the <span class="lg-highlight-title lg-highlight-class">Key</span> <span class="lg-highlight-title lg-highlight-class">Vault</span> <span class="lg-highlight-title lg-highlight-class">Collection</span> <span class="lg-highlight-keyword">in</span> <span class="lg-highlight-keyword">case</span> you created <span class="lg-highlight-variable lg-highlight-language">this</span> collection</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-keyword">in</span> a previous run <span class="lg-highlight-keyword">of</span> <span class="lg-highlight-variable lg-highlight-language">this</span> application.</td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_client.<span class="lg-highlight-title lg-highlight-function">drop_database</span>(key_vault_db)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># <span class="lg-highlight-title lg-highlight-class">Drop</span> the database storing your encrypted fields <span class="lg-highlight-keyword">as</span> all</td></tr><tr class=""><td class="leafygreen-ui-7razhx"># the <span class="lg-highlight-title lg-highlight-class">DEKs</span> encrypting those fields were deleted <span class="lg-highlight-keyword">in</span> the preceding line.</td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_client[<span class="lg-highlight-string">"medicalRecords"</span>].<span class="lg-highlight-title lg-highlight-function">drop_collection</span>(<span class="lg-highlight-string">"patients"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_client[key_vault_db][key_vault_coll].<span class="lg-highlight-title lg-highlight-function">create_index</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> [(<span class="lg-highlight-string">"keyAltNames"</span>, <span class="lg-highlight-variable lg-highlight-constant">ASCENDING</span>)],</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> unique=<span class="lg-highlight-title lg-highlight-class">True</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> partialFilterExpression={<span class="lg-highlight-string">"keyAltNames"</span>: {<span class="lg-highlight-string">"$exists"</span>: <span class="lg-highlight-title lg-highlight-class">True</span>}},</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-92-menu" aria-describedby="select-92-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-93" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r94:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r94:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r94:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r94:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create a Data Encryption Key
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-data-encryption-key" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-a-data-encryption-key">
</div>
</a>
</h3>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Add your Endpoint
</p>
<p class="leafygreen-ui-1kp3ins">
Specify the URI endpoint of your
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-17">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_ej5zieyxc" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_llyn6uefo" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_w2mzpg1c6" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_obstpydjf" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_qhzjx4hu0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pbtvqyk1t" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_zkko6hm47" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_pch6q9197" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_hc32afbsg" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_23dylw1g6" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_dcf67lvp9" class="leafygreen-ui-38lglc" id="_7n1f552ig" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var kmsProviders = new Dictionary<string,>>();\nvar provider = \"kmip\";\nvar kmipKmsOptions = new Dictionary<string,>\n{\n { \"endpoint\", \"<endpoint>\" },\n};\nkmsProviders.Add(provider, kmipKmsOptions);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> kmsProviders = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span><string, <span class="lg-highlight-title lg-highlight-class">IReadOnlyDictionary</span><string, object>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> provider = <span class="lg-highlight-string">"kmip"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> kmipKmsOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span><string, object></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"endpoint"</span>, <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders.<span class="lg-highlight-title lg-highlight-class">Add</span>(provider, kmipKmsOptions);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-95-menu" aria-describedby="select-95-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-96" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r95:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r95:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r95:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r95:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_c2qn6yzne" class="leafygreen-ui-38lglc" id="_nar2y86zm" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"provider := \"kmip\"\nkmsProviders := map[string]map[string]interface{}{\n\tprovider: {\n\t\t\"endpoint\": \"<endpoint>\",\n\t},\n}","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">provider <!-- -->:<!-- -->= <span class="lg-highlight-string">"kmip"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders <!-- -->:<!-- -->= map[string]map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"endpoint"</span>: <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-98-menu" aria-describedby="select-98-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-99" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r96:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r96:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r96:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r96:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_7rdrmm3yl" class="leafygreen-ui-38lglc" id="_141xv38kz" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String kmsProvider = \"kmip\";\nMap<string,>> kmsProviders = new HashMap<string,>>();\nMap<string,> providerDetails = new HashMap<>();\nproviderDetails.put(\"endpoint\", \"<endpoint>\");\nkmsProviders.put(kmsProvider, providerDetails);","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> kmsProvider = <span class="lg-highlight-string">"kmip"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>>> kmsProviders = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>> providerDetails = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span><>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">providerDetails.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"endpoint"</span>, <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders.<span class="lg-highlight-title lg-highlight-function">put</span>(kmsProvider, providerDetails);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-101-menu" aria-describedby="select-101-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-102" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r97:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r97:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r97:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r97:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_q3vxtx85j" class="" id="_9jcpgqp3j" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const provider = \"kmip\";\nconst kmsProviders = {\n kmip: {\n endpoint: \"<endpoint>\",\n },\n};","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> provider <!-- -->= <span class="lg-highlight-string">"kmip"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> kmsProviders <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmip</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">endpoint</span>: <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-104-menu" aria-describedby="select-104-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-105" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r98:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r98:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r98:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r98:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_7574p89rf" class="leafygreen-ui-38lglc" id="_v3w33h042" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"provider = \"kmip\"\nkms_providers = {\n provider: {\"endpoint\": \"<endpoint>\"}\n}","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">provider = <span class="lg-highlight-string">"kmip"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">kms_providers = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: {<span class="lg-highlight-string">"endpoint"</span>: <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span>}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-107-menu" aria-describedby="select-107-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-108" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r99:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r99:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r99:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r99:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Add Your Key Information
</p>
<p class="leafygreen-ui-1kp3ins">
The following code prompts your
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider to automatically generate a Customer Master Key:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-18">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_1nkvyhf44" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_jxziil3m2" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_0eanrfskz" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_a53x3xyi6" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_lsirh0ac9" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_1pmk8m2uq" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_fxxo4be2v" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_t692owyfa" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_2gdnzdxxh" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_bi4wo3grm" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_ujz3xt9pi" class="leafygreen-ui-38lglc" id="_iagjlk8ha" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var dataKeyOptions = new DataKeyOptions(\n masterKey: new BsonDocument { } // an empty key object prompts your KMIP-compliant key provider to generate a new Customer Master Key\n);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> dataKeyOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">DataKeyOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">masterKey</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span> { } <span class="lg-highlight-comment">// an</span><span class="lg-highlight-comment"> empty key object </span><span class="lg-highlight-comment">prompts</span><span class="lg-highlight-comment"> your KMIP-compliant key </span><span class="lg-highlight-comment">provider</span><span class="lg-highlight-comment"> to generate a </span><span class="lg-highlight-comment">new Customer Master Key</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-110-menu" aria-describedby="select-110-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-111" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9a:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9a:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9a:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9a:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_gb9akujnz" class="leafygreen-ui-38lglc" id="_ahwbnz7br" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"masterKey := map[string]interface{}{} // an empty key object prompts your KMIP-compliant key provider to generate a new Customer Master Key","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">masterKey <!-- -->:<!-- -->= map[string]interface{}{} <span class="lg-highlight-comment">// an</span><span class="lg-highlight-comment"> empty key object </span><span class="lg-highlight-comment">prompts</span><span class="lg-highlight-comment"> your KMIP-compliant key </span><span class="lg-highlight-comment">provider</span><span class="lg-highlight-comment"> to generate a </span><span class="lg-highlight-comment">new Customer Master Key</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-113-menu" aria-describedby="select-113-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-114" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9b:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9b:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9b:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9b:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_0j5ej137q" class="leafygreen-ui-38lglc" id="_kck1gu47e" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"BsonDocument masterKeyProperties = new BsonDocument(); // an empty key object prompts your KMIP-compliant key provider to generate a new Customer Master Key","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">BsonDocument</span> masterKeyProperties = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(); <span class="lg-highlight-comment">// an</span><span class="lg-highlight-comment"> empty key object </span><span class="lg-highlight-comment">prompts</span><span class="lg-highlight-comment"> your KMIP-compliant key </span><span class="lg-highlight-comment">provider</span><span class="lg-highlight-comment"> to generate a </span><span class="lg-highlight-comment">new Customer Master Key</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-116-menu" aria-describedby="select-116-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-117" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9c:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9c:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_11obyk5ay" class="" id="_0p0gc35zy" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const masterKey = {}; // an empty key object prompts your KMIP-compliant key provider to generate a new Customer Master Key","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> masterKey <!-- -->= <!-- -->{<!-- -->}<!-- -->; <span class="lg-highlight-comment">// an</span><span class="lg-highlight-comment"> empty key object </span><span class="lg-highlight-comment">prompts</span><span class="lg-highlight-comment"> your KMIP-compliant key </span><span class="lg-highlight-comment">provider</span><span class="lg-highlight-comment"> to generate a </span><span class="lg-highlight-comment">new Customer Master Key</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-119-menu" aria-describedby="select-119-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-120" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9d:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9d:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_cpwglo5k3" class="leafygreen-ui-38lglc" id="_2p4b2gl0w" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"master_key = (\n {}\n) # an empty key object prompts your KMIP-compliant key provider to generate a new Customer Master Key","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">master_key = (</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">) # an empty key object prompts your <span class="lg-highlight-variable lg-highlight-constant">KMIP</span>-compliant key provider to generate a <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Customer</span> <span class="lg-highlight-title lg-highlight-class">Master</span> <span class="lg-highlight-title lg-highlight-class">Key</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-122-menu" aria-describedby="select-122-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-123" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9e:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9e:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Generate your Data Encryption Key
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-kmip-create-dek">
</span>
<p class="leafygreen-ui-1kp3ins">
Generate your Data Encryption Key using the variables declared in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-csfle-kmip-create-index" target="_self">
<span>
step one
</span>
</a>
of this tutorial.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-19">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_p48eogwnz" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wjv64ybap" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_kypgc9nh0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_wvu4gybp4" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_t12t03n6g" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_03dk5a585" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_aylp7wrpm" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_dh317cjov" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_q3miq0m2e" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_x0dh0t0pk" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_ak2g6u9rf" class="leafygreen-ui-38lglc" id="_x8yxbc2rq" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var clientEncryptionOptions = new ClientEncryptionOptions(\n keyVaultClient: keyVaultClient,\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviders,\n tlsOptions: tlsOptions\n );\n\nvar clientEncryption = new ClientEncryption(clientEncryptionOptions);\nvar dataKeyId = clientEncryption.CreateDataKey(provider, dataKeyOptions, CancellationToken.None);\nvar dataKeyIdBase64 = Convert.ToBase64String(GuidConverter.ToBytes(dataKeyId, GuidRepresentation.Standard));\nConsole.WriteLine($\"DataKeyId [base64]: {dataKeyIdBase64}\");","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> clientEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryptionOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultClient</span>: keyVaultClient,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: keyVaultNamespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: kmsProviders,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tlsOptions</span>: tlsOptions</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> );</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> clientEncryption = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(clientEncryptionOptions);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> dataKeyId = clientEncryption.<span class="lg-highlight-title lg-highlight-class">CreateDataKey</span>(provider, dataKeyOptions, <span class="lg-highlight-title lg-highlight-class">CancellationToken</span>.<span class="lg-highlight-property">None</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> dataKeyIdBase64 = <span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">ToBase64String</span>(<span class="lg-highlight-title lg-highlight-class">GuidConverter</span>.<span class="lg-highlight-title lg-highlight-class">ToBytes</span>(dataKeyId, <span class="lg-highlight-title lg-highlight-class">GuidRepresentation</span>.<span class="lg-highlight-property">Standard</span>));</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>($<span class="lg-highlight-string">"DataKeyId [base64]: {dataKeyIdBase64}"</span>);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-125-menu" aria-describedby="select-125-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-126" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9f:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9f:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_wnsi86uhg" class="leafygreen-ui-38lglc" id="_9hwntv9ya" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"clientEncryptionOpts := options.ClientEncryption().SetKeyVaultNamespace(keyVaultNamespace).\n\tSetKmsProviders(kmsProviders).SetTLSConfig(tlsConfig)\nclientEnc, err := mongo.NewClientEncryption(keyVaultClient, clientEncryptionOpts)\nif err != nil {\n\treturn fmt.Errorf(\"NewClientEncryption error %v\", err)\n}\ndefer func() {\n\t_ = clientEnc.Close(context.TODO())\n}()\ndataKeyOpts := options.DataKey().\n\tSetMasterKey(masterKey)\n\ndataKeyID, err := clientEnc.CreateDataKey(context.TODO(), provider, dataKeyOpts)\nif err != nil {\n\treturn fmt.Errorf(\"create data key error %v\", err)\n}\n\nfmt.Printf(\"DataKeyId [base64]: %s\\n\", base64.StdEncoding.EncodeToString(dataKeyID.Data))","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">clientEncryptionOpts <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>().<span class="lg-highlight-title lg-highlight-class">SetKeyVaultNamespace</span>(keyVaultNamespace).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKmsProviders</span>(kmsProviders).<span class="lg-highlight-title lg-highlight-class">SetTLSConfig</span>(tlsConfig)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientEnc<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">NewClientEncryption</span>(keyVaultClient, clientEncryptionOpts)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"NewClientEncryption error %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">defer <span class="lg-highlight-title lg-highlight-function">func</span>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _ = clientEnc.<span class="lg-highlight-title lg-highlight-class">Close</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">dataKeyOpts <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">DataKey</span>().</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetMasterKey</span>(masterKey)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">dataKeyID<!-- -->, <!-- -->err := clientEnc.<span class="lg-highlight-title lg-highlight-class">CreateDataKey</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), provider, dataKeyOpts)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"create data key error %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">fmt.<span class="lg-highlight-title lg-highlight-class">Printf</span>(<span class="lg-highlight-string">"DataKeyId [base64]: %s</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, base64.<span class="lg-highlight-property">StdEncoding</span>.<span class="lg-highlight-title lg-highlight-class">EncodeToString</span>(dataKeyID.<span class="lg-highlight-property">Data</span>))</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-128-menu" aria-describedby="select-128-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-129" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9g:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9g:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_4lwsf3hoj" class="leafygreen-ui-38lglc" id="_9sixohpx1" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()\n .keyVaultMongoClientSettings(MongoClientSettings.builder()\n .applyConnectionString(new ConnectionString(connectionString))\n .build())\n .keyVaultNamespace(keyVaultNamespace)\n .kmsProviders(kmsProviders)\n .build();\n\nMongoClient regularClient = MongoClients.create(connectionString);\n\nClientEncryption clientEncryption = ClientEncryptions.create(clientEncryptionSettings);\nBsonBinary dataKeyId = clientEncryption.createDataKey(kmsProvider, new DataKeyOptions().masterKey(masterKeyProperties));\nString base64DataKeyId = Base64.getEncoder().encodeToString(dataKeyId.getData());\nSystem.out.println(\"DataKeyId [base64]: \" + base64DataKeyId);\nclientEncryption.close();","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">ClientEncryptionSettings</span> clientEncryptionSettings = <span class="lg-highlight-title lg-highlight-class">ClientEncryptionSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultMongoClientSettings</span>(<span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">applyConnectionString</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ConnectionString</span>(connectionString))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultNamespace</span>(keyVaultNamespace)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">kmsProviders</span>(kmsProviders)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoClient</span> regularClient = <span class="lg-highlight-title lg-highlight-class">MongoClients</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(connectionString);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">ClientEncryption</span> clientEncryption = <span class="lg-highlight-title lg-highlight-class">ClientEncryptions</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(clientEncryptionSettings);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">BsonBinary</span> dataKeyId = clientEncryption.<span class="lg-highlight-title lg-highlight-function">createDataKey</span>(kmsProvider, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">DataKeyOptions</span>().<span class="lg-highlight-title lg-highlight-function">masterKey</span>(masterKeyProperties));</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> base64DataKeyId = <span class="lg-highlight-title lg-highlight-class">Base64</span>.<span class="lg-highlight-title lg-highlight-function">getEncoder</span>().<span class="lg-highlight-title lg-highlight-function">encodeToString</span>(dataKeyId.<span class="lg-highlight-title lg-highlight-function">getData</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(<span class="lg-highlight-string">"DataKeyId [base64]: "</span> + base64DataKeyId);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientEncryption.<span class="lg-highlight-title lg-highlight-function">close</span>();</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-131-menu" aria-describedby="select-131-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-132" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9h:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9h:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_wrrlivu8c" class="" id="_ipb4aosf2" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const client = new MongoClient(uri);\nawait client.connect();\n\nconst encryption = new ClientEncryption(client, {\n keyVaultNamespace,\n kmsProviders,\n tlsOptions,\n});\nconst key = await encryption.createDataKey(provider, {\n masterKey: masterKey,\n});\nconsole.log(\"DataKeyId [base64]: \", key.toString(\"base64\"));\nawait keyVaultClient.close();\nawait client.close();","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> client <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(<!-- -->uri)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> client.<span class="lg-highlight-title lg-highlight-function">connect</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> encryption <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(<!-- -->client<!-- -->, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->keyVaultNamespace<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->kmsProviders<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->tlsOptions<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> key <!-- -->= <span class="lg-highlight-keyword">await</span> encryption.<span class="lg-highlight-title lg-highlight-function">createDataKey</span>(<!-- -->provider<!-- -->, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">masterKey</span>: <!-- -->masterKey<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(<span class="lg-highlight-string">"DataKeyId [base64]: "</span>, <!-- -->key.<span class="lg-highlight-title lg-highlight-function">toString</span>(<span class="lg-highlight-string">"base64"</span>))<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> keyVaultClient.<span class="lg-highlight-title lg-highlight-function">close</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">await</span> client.<span class="lg-highlight-title lg-highlight-function">close</span>(<!-- -->)<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-134-menu" aria-describedby="select-134-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-135" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9i:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9i:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Import ClientEncryption
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
When using the Node.js driver v6.0 and later, you must import
<code class="leafygreen-ui-1l06pbn">
ClientEncryption
</code>
from
<code class="leafygreen-ui-1l06pbn">
mongodb
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For earlier driver versions, import
<code class="leafygreen-ui-1l06pbn">
ClientEncryption
</code>
from
<code class="leafygreen-ui-1l06pbn">
mongodb-client-encryption
</code>
.
</p>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ynn0k59ko" class="leafygreen-ui-38lglc" id="_ja2bl8yhd" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"key_vault_database = \"encryption\"\nkey_vault_collection = \"__keyVault\"\nkey_vault_namespace = f\"{key_vault_database}.{key_vault_collection}\"\n\nclient = MongoClient(connection_string)\nclient_encryption = ClientEncryption(\n kms_providers, # pass in the kms_providers variable from the previous step\n key_vault_namespace,\n client,\n CodecOptions(uuid_representation=STANDARD),\n kms_tls_options=tls_options,\n)\ndata_key_id = client_encryption.create_data_key(provider, master_key)\n\nbase_64_data_key_id = base64.b64encode(data_key_id)\nprint(\"DataKeyId [base64]: \", base_64_data_key_id)","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">key_vault_database = <span class="lg-highlight-string">"encryption"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_collection = <span class="lg-highlight-string">"__keyVault"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">key_vault_namespace = f<span class="lg-highlight-string">"{key_vault_database}.{key_vault_collection}"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">client = <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connection_string)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">client_encryption = <span class="lg-highlight-title lg-highlight-class">ClientEncryption</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_providers, # pass <span class="lg-highlight-keyword">in</span> the kms_providers variable <span class="lg-highlight-keyword">from</span> the previous step</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key_vault_namespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> client,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">CodecOptions</span>(uuid_representation=<span class="lg-highlight-variable lg-highlight-constant">STANDARD</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_tls_options=tls_options,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">data_key_id = client_encryption.<span class="lg-highlight-title lg-highlight-function">create_data_key</span>(provider, master_key)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">base_64_data_key_id = base64.<span class="lg-highlight-title lg-highlight-function">b64encode</span>(data_key_id)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">print</span>(<span class="lg-highlight-string">"DataKeyId [base64]: "</span>, base_64_data_key_id)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-137-menu" aria-describedby="select-137-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-138" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9j:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9j:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
</ol>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See: Complete Code
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-20">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_bx1zyjhv1" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_se5f258d2" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_7a4yctd7z" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_q3gy1nf7p" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_tvudj50bl" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_nt68q2rk9" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_rqd6rmgec" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_jqa7ypze9" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_pphtcpdiu" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_kzb5e8bck" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_7l7opqxbp" class="leafygreen-ui-38lglc" id="_wwwm78g7o" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for making a Data Encryption Key, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/kmip/reader/CSFLE/MakeDataKey.cs" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ej72ye0vq" class="leafygreen-ui-38lglc" id="_r11phahll" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for making a Data Encryption Key, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/kmip/reader/make-data-key.go" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_28f3mh3mn" class="leafygreen-ui-38lglc" id="_ja57kts70" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for making a Data Encryption Key, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/kmip/reader/src/main/java/com/mongodb/csfle/MakeDataKey.java" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_4luvhu31y" class="" id="_kx5uoxh10" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for making a Data Encryption Key, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/kmip/reader/make_data_key.js" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_k8sbew5a5" class="leafygreen-ui-38lglc" id="_vqvidbscw" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for making a Data Encryption Key, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/kmip/reader/make_data_key.py" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Configure the MongoClient
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-the-mongoclient" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configure-the-mongoclient">
</div>
</a>
</h3>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Follow the remaining steps in this tutorial in a separate file
from the one created in the previous steps.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-22">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_2ob4989vt" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_jjtg6taqs" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_ltyo3pgwg" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_jnw149fhc" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_gvzwij315" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pb4gcslsr" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_zin18yqbe" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_n7f7helem" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_dnxau8vl3" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_bl8l55bvy" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_45hqlqtww" class="leafygreen-ui-38lglc" id="_wtetq5xsf" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for this file, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/kmip/reader/CSFLE/InsertEncryptedDocument.cs" rel="noopener noreferrer">
<span>
our Github repository
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_o2ba4545j" class="leafygreen-ui-38lglc" id="_7kr6el6uu" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for this file, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/kmip/reader/insert-encrypted-document.go" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_9qhdwfzbk" class="leafygreen-ui-38lglc" id="_e3sk77t8a" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for this file, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/kmip/reader/src/main/java/com/mongodb/csfle/InsertEncryptedDocument.java" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_t4klcpw09" class="" id="_y14apt9wx" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for this file, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/kmip/reader/insert_encrypted_document.js" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_q0mbq2kch" class="leafygreen-ui-38lglc" id="_rjz7o4byc" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for this file, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/kmip/reader/insert_encrypted_document.py" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specify the Key Vault Collection Namespace
</p>
<p class="leafygreen-ui-1kp3ins">
Specify
<code class="leafygreen-ui-1l06pbn">
encryption.__keyVault
</code>
as the Key Vault collection
namespace.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-23">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_vhxa5a6ze" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_v7lyeeciz" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_asf6niycu" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_g4cllk8i8" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_pgr2h00qx" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_5q6da3ya6" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_hgz6fq5uv" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_eo5k22jmv" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_tmyjb6p3b" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ap85b11jv" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_w9ezdaqxu" class="leafygreen-ui-38lglc" id="_r37493y51" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var keyVaultNamespace = CollectionNamespace.FromFullName(\"encryption.__keyVault\");","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyVaultNamespace = <span class="lg-highlight-title lg-highlight-class">CollectionNamespace</span>.<span class="lg-highlight-title lg-highlight-class">FromFullName</span>(<span class="lg-highlight-string">"encryption.__keyVault"</span>);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-140-menu" aria-describedby="select-140-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-141" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9k:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9k:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_mnd2gv2j0" class="leafygreen-ui-38lglc" id="_qid7gnuar" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"keyVaultNamespace := \"encryption.__keyVault\"","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">keyVaultNamespace <!-- -->:<!-- -->= <span class="lg-highlight-string">"encryption.__keyVault"</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-143-menu" aria-describedby="select-143-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-144" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9l:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9l:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_cxvd72gyo" class="leafygreen-ui-38lglc" id="_bp6ypgjll" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String keyVaultNamespace = \"encryption.__keyVault\";","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> keyVaultNamespace = <span class="lg-highlight-string">"encryption.__keyVault"</span>;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-146-menu" aria-describedby="select-146-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-147" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9m:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9m:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_f2gk1o46t" class="" id="_rq7ejeck0" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const keyVaultNamespace = \"encryption.__keyVault\";","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> keyVaultNamespace <!-- -->= <span class="lg-highlight-string">"encryption.__keyVault"</span>;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-149-menu" aria-describedby="select-149-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-150" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9n:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9n:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_zoq7ok1o6" class="leafygreen-ui-38lglc" id="_6o1eteuy9" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"key_vault_namespace = \"encryption.__keyVault\"","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">key_vault_namespace = <span class="lg-highlight-string">"encryption.__keyVault"</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-152-menu" aria-describedby="select-152-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-153" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9o:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9o:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specify your KMIP Endpoint
</p>
<p class="leafygreen-ui-1kp3ins">
Specify
<code class="leafygreen-ui-1l06pbn">
kmip
</code>
in your
<code class="leafygreen-ui-1l06pbn">
kmsProviders
</code>
object and enter
the URI endpoint of your
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMIP
</span>
-compliant key provider:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-24">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_6fq3rzv0x" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_lojy8uwdq" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_mw7kb0ww8" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_hhgc1pjw0" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_32udce8md" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pegkyha4a" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_zc17fdo6h" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_zg1o9w5bg" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_xv2e61k5d" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_mu8rvp1nl" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_29c1frouk" class="leafygreen-ui-38lglc" id="_t8sieqwzi" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var kmsProviders = new Dictionary<string,>>();\nvar provider = \"kmip\";\nvar kmipKmsOptions = new Dictionary<string,>\n{\n { \"endpoint\", \"<endpoint>\" },\n};\nkmsProviders.Add(provider, kmipKmsOptions);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> kmsProviders = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span><string, <span class="lg-highlight-title lg-highlight-class">IReadOnlyDictionary</span><string, object>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> provider = <span class="lg-highlight-string">"kmip"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> kmipKmsOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span><string, object></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"endpoint"</span>, <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders.<span class="lg-highlight-title lg-highlight-class">Add</span>(provider, kmipKmsOptions);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-155-menu" aria-describedby="select-155-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-156" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9p:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9p:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_imnxzh52w" class="leafygreen-ui-38lglc" id="_xanw7zl2i" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"provider := \"kmip\"\nkmsProviders := map[string]map[string]interface{}{\n\tprovider: {\n\t\t\"endpoint\": \"<endpoint>\",\n\t},\n}","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">provider <!-- -->:<!-- -->= <span class="lg-highlight-string">"kmip"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders <!-- -->:<!-- -->= map[string]map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"endpoint"</span>: <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-158-menu" aria-describedby="select-158-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-159" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9q:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9q:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9q:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9q:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_l5k3e51qe" class="leafygreen-ui-38lglc" id="_enyjsjayi" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String kmsProvider = \"kmip\";\nMap<string,>> kmsProviders = new HashMap<string,>>();\nMap<string,> providerDetails = new HashMap<>();\nproviderDetails.put(\"endpoint\", \"<endpoint>\");\nkmsProviders.put(kmsProvider, providerDetails);","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> kmsProvider = <span class="lg-highlight-string">"kmip"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>>> kmsProviders = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>> providerDetails = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span><>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">providerDetails.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"endpoint"</span>, <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">kmsProviders.<span class="lg-highlight-title lg-highlight-function">put</span>(kmsProvider, providerDetails);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-161-menu" aria-describedby="select-161-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-162" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9r:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9r:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9r:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9r:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_9nmdzvksq" class="" id="_f1ffeoj4c" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const provider = \"kmip\";\nconst kmsProviders = {\n kmip: {\n endpoint: \"<endpoint>\",\n },\n};","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> provider <!-- -->= <span class="lg-highlight-string">"kmip"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> kmsProviders <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmip</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">endpoint</span>: <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-164-menu" aria-describedby="select-164-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-165" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9s:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9s:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9s:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9s:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_50x4ufaxw" class="leafygreen-ui-38lglc" id="_d10r1yuaj" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"provider = \"kmip\"\nkms_providers = {\n provider: {\"endpoint\": \"<endpoint>\"}\n}","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">provider = <span class="lg-highlight-string">"kmip"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">kms_providers = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: {<span class="lg-highlight-string">"endpoint"</span>: <span class="lg-highlight-string">"<endpoint for your KMIP-compliant key provider>"</span>}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-167-menu" aria-describedby="select-167-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-168" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9t:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9t:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9t:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9t:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Create an Encryption Schema For Your Collection
</p>
<p class="leafygreen-ui-1kp3ins">
Create an encryption schema that specifies how your client
application encrypts your documents' fields:
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Add Your Data Encryption Key Base64 ID
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Make sure to update the following code to include your Base64
<span class="leafygreen-ui-vm4wms" tabindex="0">
DEK
</span>
ID. You received this value in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-csfle-kmip-create-dek" target="_self">
<span>
Generate your Data Encryption Key
</span>
</a>
step of this
guide.
</p>
</div>
</div>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-25">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_e61unvtkz" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_nc9pk7opr" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_6dao8msom" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_yy39l6kfr" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_fwi5w1xk9" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_d0zlqhtq6" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_xjdz0gfg1" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_prvmbkd6w" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_jsi6ay3e8" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_pl80g8356" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_u4synv0pf" class="leafygreen-ui-38lglc" id="_370vjsssb" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var keyId = \"<your>\";\nvar schema = new BsonDocument\n{\n { \"bsonType\", \"object\" },\n {\n \"encryptMetadata\",\n new BsonDocument(\"keyId\", new BsonArray(new[] { new BsonBinaryData(Convert.FromBase64String(keyId), BsonBinarySubType.UuidStandard) }))\n },\n {\n \"properties\",\n new BsonDocument\n {\n {\n \"ssn\", new BsonDocument\n {\n {\n \"encrypt\", new BsonDocument\n {\n { \"bsonType\", \"int\" },\n { \"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\" }\n }\n }\n }\n },\n {\n \"bloodType\", new BsonDocument\n {\n {\n \"encrypt\", new BsonDocument\n {\n { \"bsonType\", \"string\" },\n { \"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\" }\n }\n }\n }\n },\n {\n \"medicalRecords\", new BsonDocument\n {\n {\n \"encrypt\", new BsonDocument\n {\n { \"bsonType\", \"array\" },\n { \"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\" }\n }\n }\n }\n },\n {\n \"insurance\", new BsonDocument\n {\n { \"bsonType\", \"object\" },\n {\n \"properties\", new BsonDocument\n {\n {\n \"policyNumber\", new BsonDocument\n {\n {\n \"encrypt\", new BsonDocument\n {\n { \"bsonType\", \"int\" },\n { \"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\" }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n};\nvar schemaMap = new Dictionary<string,>();\nschemaMap.Add(dbNamespace, schema);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> keyId = <span class="lg-highlight-string">"<Your base64 DEK ID here>"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> schema = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encryptMetadata"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"keyId"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonArray</span>(<span class="lg-highlight-keyword">new</span>[] { <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonBinaryData</span>(<span class="lg-highlight-title lg-highlight-class">Convert</span>.<span class="lg-highlight-title lg-highlight-class">FromBase64String</span>(keyId), <span class="lg-highlight-title lg-highlight-class">BsonBinarySubType</span>.<span class="lg-highlight-property">UuidStandard</span>) }))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"properties"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"int"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodType"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"string"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"array"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"properties"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"policyNumber"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"int"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> schemaMap = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span><string, <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">schemaMap.<span class="lg-highlight-title lg-highlight-class">Add</span>(dbNamespace, schema);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-170-menu" aria-describedby="select-170-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-171" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9u:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9u:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9u:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9u:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_t80tr5ax0" class="leafygreen-ui-38lglc" id="_vjhdf3o72" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dek_id := \"<your>\"\nschema_template := `{\n\t\"bsonType\": \"object\",\n\t\"encryptMetadata\": {\n\t\t\"keyId\": [\n\t\t\t{\n\t\t\t\t\"$binary\": {\n\t\t\t\t\t\"base64\": \"%s\",\n\t\t\t\t\t\"subType\": \"04\"\n\t\t\t\t}\n\t\t\t}\n\t\t]\n\t},\n\t\"properties\": {\n\t\t\"insurance\": {\n\t\t\t\"bsonType\": \"object\",\n\t\t\t\"properties\": {\n\t\t\t\t\"policyNumber\": {\n\t\t\t\t\t\"encrypt\": {\n\t\t\t\t\t\t\"bsonType\": \"int\",\n\t\t\t\t\t\t\"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"medicalRecords\": {\n\t\t\t\"encrypt\": {\n\t\t\t\t\"bsonType\": \"array\",\n\t\t\t\t\"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\"\n\t\t\t}\n\t\t},\n\t\t\"bloodType\": {\n\t\t\t\"encrypt\": {\n\t\t\t\t\"bsonType\": \"string\",\n\t\t\t\t\"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\"\n\t\t\t}\n\t\t},\n\t\t\"ssn\": {\n\t\t\t\"encrypt\": {\n\t\t\t\t\"bsonType\": \"int\",\n\t\t\t\t\"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\"\n\t\t\t}\n\t\t}\n\t}\n}`\nschema := fmt.Sprintf(schema_template, dek_id)\nvar schemaDoc bson.Raw\nif err := bson.UnmarshalExtJSON([]byte(schema), true, &schemaDoc); err != nil {\n\treturn fmt.Errorf(\"UnmarshalExtJSON error: %v\", err)\n}\nschemaMap := map[string]interface{}{\n\tdbName + \".\" + collName: schemaDoc,\n}","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">dek_id <!-- -->:<!-- -->= <span class="lg-highlight-string">"<Your Base64 DEK ID>"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">schema_template <!-- -->:<!-- -->= <span class="lg-highlight-string">`{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "object",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encryptMetadata": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "keyId": [</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "$binary": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "base64": "%s",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "subType": "04"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> ]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "properties": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "insurance": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "object",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "properties": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "policyNumber": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encrypt": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "int",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "medicalRecords": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encrypt": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "array",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bloodType": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encrypt": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "string",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> },</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "ssn": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "encrypt": {</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "bsonType": "int",</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">}`</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">schema <!-- -->:<!-- -->= fmt.<span class="lg-highlight-title lg-highlight-class">Sprintf</span>(schema_template, dek_id)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> schemaDoc bson.<span class="lg-highlight-property">Raw</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err <!-- -->:<!-- -->= bson.<span class="lg-highlight-title lg-highlight-class">UnmarshalExtJSON</span>([]<span class="lg-highlight-title lg-highlight-function">byte</span>(schema), <span class="lg-highlight-literal">true</span>, &schemaDoc); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"UnmarshalExtJSON error: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">schemaMap <!-- -->:<!-- -->= map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> dbName + <span class="lg-highlight-string">"."</span> + <span class="lg-highlight-attr">collName</span>: schemaDoc,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-173-menu" aria-describedby="select-173-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-174" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r9v:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r9v:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9v:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r9v:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_zd1g0l0au" class="leafygreen-ui-38lglc" id="_bpkaqoqf1" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"String dekId = \"<paste-base-64-encoded-data-encryption-key-id>>\";\nDocument jsonSchema = new Document().append(\"bsonType\", \"object\").append(\"encryptMetadata\",\n new Document().append(\"keyId\", new ArrayList<>((Arrays.asList(new Document().append(\"$binary\", new Document()\n .append(\"base64\", dekId)\n .append(\"subType\", \"04\")))))))\n .append(\"properties\", new Document()\n .append(\"ssn\", new Document().append(\"encrypt\", new Document()\n .append(\"bsonType\", \"int\")\n .append(\"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\")))\n .append(\"bloodType\", new Document().append(\"encrypt\", new Document()\n .append(\"bsonType\", \"string\")\n .append(\"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\")))\n .append(\"medicalRecords\", new Document().append(\"encrypt\", new Document()\n .append(\"bsonType\", \"array\")\n .append(\"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\")))\n .append(\"insurance\", new Document()\n .append(\"bsonType\", \"object\")\n .append(\"properties\",\n new Document().append(\"policyNumber\", new Document().append(\"encrypt\", new Document()\n .append(\"bsonType\", \"int\")\n .append(\"algorithm\", \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\"))))));\nHashMap<string,> schemaMap = new HashMap<string,>();\nschemaMap.put(\"medicalRecords.patients\", BsonDocument.parse(jsonSchema.toJson()));","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">String</span> dekId = <span class="lg-highlight-string">"<paste-base-64-encoded-data-encryption-key-id>>"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Document</span> jsonSchema = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span>).<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encryptMetadata"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"keyId"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ArrayList</span><>((<span class="lg-highlight-title lg-highlight-class">Arrays</span>.<span class="lg-highlight-title lg-highlight-function">asList</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"$binary"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"base64"</span>, dekId)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"subType"</span>, <span class="lg-highlight-string">"04"</span>)))))))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"properties"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"ssn"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"int"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>)))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bloodType"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"string"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>)))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"medicalRecords"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"array"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>)))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"insurance"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"object"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"properties"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"policyNumber"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"encrypt"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bsonType"</span>, <span class="lg-highlight-string">"int"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"algorithm"</span>, <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>))))));</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">HashMap</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>> schemaMap = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">schemaMap.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"medicalRecords.patients"</span>, <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>.<span class="lg-highlight-title lg-highlight-function">parse</span>(jsonSchema.<span class="lg-highlight-title lg-highlight-function">toJson</span>()));</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-176-menu" aria-describedby="select-176-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-177" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra0:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra0:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra0:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra0:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_zxns50dl2" class="" id="_a2s62wf0w" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dataKey = \"<your>\";\nconst schema = {\n bsonType: \"object\",\n encryptMetadata: {\n keyId: [new Binary(Buffer.from(dataKey, \"base64\"), 4)],\n },\n properties: {\n insurance: {\n bsonType: \"object\",\n properties: {\n policyNumber: {\n encrypt: {\n bsonType: \"int\",\n algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\",\n },\n },\n },\n },\n medicalRecords: {\n encrypt: {\n bsonType: \"array\",\n algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\",\n },\n },\n bloodType: {\n encrypt: {\n bsonType: \"string\",\n algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\",\n },\n },\n ssn: {\n encrypt: {\n bsonType: \"int\",\n algorithm: \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\",\n },\n },\n },\n};\n\nvar patientSchema = {};\npatientSchema[namespace] = schema;","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">dataKey <!-- -->= <span class="lg-highlight-string">"<Your base64 DEK ID>"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> schema <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptMetadata</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyId</span>: <!-- -->[<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Binary</span>(<span class="lg-highlight-title lg-highlight-class">Buffer</span>.<span class="lg-highlight-title lg-highlight-function">from</span>(<!-- -->dataKey<!-- -->, <span class="lg-highlight-string">"base64"</span>)<!-- -->, <span class="lg-highlight-number">4</span>)]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">properties</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insurance</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">properties</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">policyNumber</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encrypt</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"int"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">medicalRecords</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encrypt</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"array"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bloodType</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encrypt</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"string"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ssn</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encrypt</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bsonType</span>: <span class="lg-highlight-string">"int"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> patientSchema <!-- -->= <!-- -->{<!-- -->}<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">patientSchema<!-- -->[<!-- -->namespace] <!-- -->= <!-- -->schema<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-179-menu" aria-describedby="select-179-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-180" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra1:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra1:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra1:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra1:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_2so2d900j" class="leafygreen-ui-38lglc" id="_bg2y7uv3t" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"dek_id = b\"<paste-base-64-encoded-data-encryption-key-id>\"\njson_schema = {\n \"bsonType\": \"object\",\n \"encryptMetadata\": {\"keyId\": [Binary(base64.b64decode(dek_id), UUID_SUBTYPE)]},\n \"properties\": {\n \"insurance\": {\n \"bsonType\": \"object\",\n \"properties\": {\n \"policyNumber\": {\n \"encrypt\": {\n \"bsonType\": \"int\",\n \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\",\n }\n }\n },\n },\n \"medicalRecords\": {\n \"encrypt\": {\n \"bsonType\": \"array\",\n \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\",\n }\n },\n \"bloodType\": {\n \"encrypt\": {\n \"bsonType\": \"string\",\n \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Random\",\n }\n },\n \"ssn\": {\n \"encrypt\": {\n \"bsonType\": \"int\",\n \"algorithm\": \"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic\",\n }\n },\n },\n}\n\npatient_schema = {\"medicalRecords.patients\": json_schema}","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">dek_id = b<span class="lg-highlight-string">"<paste-base-64-encoded-data-encryption-key-id>"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">json_schema = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encryptMetadata"</span>: {<span class="lg-highlight-string">"keyId"</span>: [<span class="lg-highlight-title lg-highlight-class">Binary</span>(base64.<span class="lg-highlight-title lg-highlight-function">b64decode</span>(dek_id), <span class="lg-highlight-variable lg-highlight-constant">UUID_SUBTYPE</span>)]},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"properties"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"object"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"properties"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"policyNumber"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"int"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"algorithm"</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"array"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"algorithm"</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodType"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"string"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"algorithm"</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Random"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"encrypt"</span>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bsonType"</span>: <span class="lg-highlight-string">"int"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"algorithm"</span>: <span class="lg-highlight-string">"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">patient_schema = {<span class="lg-highlight-string">"medicalRecords.patients"</span>: json_schema}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-182-menu" aria-describedby="select-182-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-183" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra2:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra2:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra2:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra2:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Further Reading on Schemas
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To view an in-depth description of how to construct the schema you use
in this step, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/create-schema/#std-label-csfle-fundamentals-create-schema">
Encryption Schemas
</a>
guide.
</p>
<p class="leafygreen-ui-1kp3ins">
To view a list of all supported encryption rules for your
encryption schemas, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/encryption-schemas/#std-label-csfle-reference-encryption-schemas">
CSFLE Encryption Schemas
</a>
guide.
</p>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specify the Location of the Automatic Encryption Shared Library
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-26">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_t2u3hxxu6" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_0ge1dpte0" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_kdmtv2evd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_huzpwydc9" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_9z9p6954i" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_eqbillowg" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_2wbq1pvi2" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_pmhjr3gib" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_rw1skauk5" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ynphfwiap" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_rg0yybtpw" class="leafygreen-ui-38lglc" id="_5gobyt383" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var mongoBinariesPath = \"<full>\";\nvar extraOptions = new Dictionary<string,>()\n{\n { \"cryptSharedLibPath\", mongoBinariesPath },\n};","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> mongoBinariesPath = <span class="lg-highlight-string">"<Full path to your Automatic Encryption Shared Library>"</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> extraOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Dictionary</span><string, object>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"cryptSharedLibPath"</span>, mongoBinariesPath },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-185-menu" aria-describedby="select-185-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-186" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra3:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra3:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra3:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra3:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_5gfttnlhp" class="leafygreen-ui-38lglc" id="_tx3rfr9aq" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"extraOptions := map[string]interface{}{\n\t\"cryptSharedLibPath\": \"<full>\",\n}","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">extraOptions <!-- -->:<!-- -->= map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"cryptSharedLibPath"</span>: <span class="lg-highlight-string">"<Full path to your Automatic Encryption Shared Library>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-188-menu" aria-describedby="select-188-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-189" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra4:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra4:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra4:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra4:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_3i5ezu1jg" class="leafygreen-ui-38lglc" id="_jwe3vbk97" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Map<string,> extraOptions = new HashMap<string,>();\nextraOptions.put(\"cryptSharedLibPath\", \"<full>\"));","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Map</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>> extraOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">HashMap</span><<span class="lg-highlight-title lg-highlight-class">String</span>, <span class="lg-highlight-title lg-highlight-class">Object</span>>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">extraOptions.<span class="lg-highlight-title lg-highlight-function">put</span>(<span class="lg-highlight-string">"cryptSharedLibPath"</span>, <span class="lg-highlight-string">"<Full path to your Automatic Encryption Shared Library>"</span>));</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-191-menu" aria-describedby="select-191-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-192" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra5:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra5:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra5:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra5:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_enjref0zb" class="" id="_y7ej3zo2m" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const extraOptions = {\n cryptSharedLibPath: \"<full>\",\n};","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> extraOptions <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cryptSharedLibPath</span>: <span class="lg-highlight-string">"<Full path to your Automatic Encryption Shared Library>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-194-menu" aria-describedby="select-194-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-195" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra6:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra6:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra6:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra6:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_67o17p7ip" class="leafygreen-ui-38lglc" id="_xag1wzsz5" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"extra_options = {\n \"cryptSharedLibPath\": \"<full>\"\n}","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">extra_options = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"cryptSharedLibPath"</span>: <span class="lg-highlight-string">"<Full path to your Automatic Encryption Shared Library>"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-197-menu" aria-describedby="select-197-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-198" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra7:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra7:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra7:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra7:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Automatic Encryption Options
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The automatic encryption options provide configuration
information to the Automatic Encryption Shared Library,
which modifies the application's behavior when accessing encrypted fields.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about the Automatic Encryption Shared Library, see
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/install-library/#std-label-csfle-reference-shared-library">
Install and Configure a CSFLE Library
</a>
page.
</p>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Create the MongoClient
</p>
<p class="leafygreen-ui-1kp3ins">
Instantiate a MongoDB client object with the following automatic
encryption settings that use the variables declared in the previous steps:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-28">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_uuuckbyx0" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xcahotqhu" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_1ddg7afif" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_sdy3d5vna" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_79mazuc6f" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_1od8h7fjq" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_abe55yhu8" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_fvz1t5g8h" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_i4r8y5eu8" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_b9h3xf47x" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_n7ev1g65t" class="leafygreen-ui-38lglc" id="_dxbv26l71" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-27">
<div aria-label="Tabs to describe usage of csharp-v2/csharp-v3" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_zyxxtje1b" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_8kjk0oes5" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
C# Driver v3.0+
</div>
</button>
<button aria-controls="_vajn8gkrl" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_8x94nsirf" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C# Driver < v3.0
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_od1j7mlg2" class="" id="_ak97ac61p" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoClientSettings.Extensions.AddAutoEncryption(); // .NET/C# Driver v3.0 or later only\nvar clientSettings = MongoClientSettings.FromConnectionString(connectionString);\nvar autoEncryptionOptions = new AutoEncryptionOptions(\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviders,\n schemaMap: schemaMap,\n extraOptions: extraOptions,\n tlsOptions: tlsOptions\n );\nclientSettings.AutoEncryptionOptions = autoEncryptionOptions;\nvar secureClient = new MongoClient(clientSettings);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-property">Extensions</span>.<span class="lg-highlight-title lg-highlight-class">AddAutoEncryption</span>(); <span class="lg-highlight-comment">// .NET/C# Driver v3.0 or later only</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-class">FromConnectionString</span>(connectionString);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> autoEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: keyVaultNamespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: kmsProviders,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaMap</span>: schemaMap,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: extraOptions,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tlsOptions</span>: tlsOptions</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> );</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientSettings.<span class="lg-highlight-property">AutoEncryptionOptions</span> = autoEncryptionOptions;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> secureClient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(clientSettings);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-200-menu" aria-describedby="select-200-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-201" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra8:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra8:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra8:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra8:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ixpzoi3m7" class="leafygreen-ui-38lglc" id="_7leioyh4f" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var clientSettings = MongoClientSettings.FromConnectionString(connectionString);\nvar autoEncryptionOptions = new AutoEncryptionOptions(\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviders,\n schemaMap: schemaMap,\n extraOptions: extraOptions,\n tlsOptions: tlsOptions\n );\nclientSettings.AutoEncryptionOptions = autoEncryptionOptions;\nvar secureClient = new MongoClient(clientSettings);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-class">FromConnectionString</span>(connectionString);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> autoEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOptions</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: keyVaultNamespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: kmsProviders,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaMap</span>: schemaMap,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: extraOptions,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tlsOptions</span>: tlsOptions</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> );</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientSettings.<span class="lg-highlight-property">AutoEncryptionOptions</span> = autoEncryptionOptions;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> secureClient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(clientSettings);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-203-menu" aria-describedby="select-203-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-204" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ra9:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ra9:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra9:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ra9:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ztlhd35e4" class="leafygreen-ui-38lglc" id="_pf6jwl7ix" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"autoEncryptionOpts := options.AutoEncryption().\n\tSetKmsProviders(kmsProviders).\n\tSetKeyVaultNamespace(keyVaultNamespace).\n\tSetSchemaMap(schemaMap).\n\tSetExtraOptions(extraOptions).SetTLSConfig(tlsConfig)\nsecureClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri).SetAutoEncryptionOptions(autoEncryptionOpts))\nif err != nil {\n\treturn fmt.Errorf(\"Connect error for encrypted client: %v\", err)\n}\ndefer func() {\n\t_ = secureClient.Disconnect(context.TODO())\n}()","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">autoEncryptionOpts <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">AutoEncryption</span>().</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKmsProviders</span>(kmsProviders).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKeyVaultNamespace</span>(keyVaultNamespace).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetSchemaMap</span>(schemaMap).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetExtraOptions</span>(extraOptions).<span class="lg-highlight-title lg-highlight-class">SetTLSConfig</span>(tlsConfig)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">secureClient<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">Connect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), options.<span class="lg-highlight-title lg-highlight-class">Client</span>().<span class="lg-highlight-title lg-highlight-class">ApplyURI</span>(uri).<span class="lg-highlight-title lg-highlight-class">SetAutoEncryptionOptions</span>(autoEncryptionOpts))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"Connect error for encrypted client: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">defer <span class="lg-highlight-title lg-highlight-function">func</span>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _ = secureClient.<span class="lg-highlight-title lg-highlight-class">Disconnect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}()</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-206-menu" aria-describedby="select-206-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-207" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:raa:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":raa:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":raa:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":raa:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_o620z22jy" class="leafygreen-ui-38lglc" id="_83yuxaito" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoClientSettings clientSettings = MongoClientSettings.builder()\n .applyConnectionString(new ConnectionString(connectionString))\n .autoEncryptionSettings(AutoEncryptionSettings.builder()\n .keyVaultNamespace(keyVaultNamespace)\n .kmsProviders(kmsProviders)\n .schemaMap(schemaMap)\n .extraOptions(extraOptions)\n .build())\n .build();\n\nMongoClient mongoClientSecure = MongoClients.create(clientSettings);","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">applyConnectionString</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ConnectionString</span>(connectionString))</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">autoEncryptionSettings</span>(<span class="lg-highlight-title lg-highlight-class">AutoEncryptionSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultNamespace</span>(keyVaultNamespace)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">kmsProviders</span>(kmsProviders)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">schemaMap</span>(schemaMap)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">extraOptions</span>(extraOptions)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoClient</span> mongoClientSecure = <span class="lg-highlight-title lg-highlight-class">MongoClients</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(clientSettings);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-209-menu" aria-describedby="select-209-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-210" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rab:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rab:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rab:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rab:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_oe9os91j1" class="" id="_x6qu9up1l" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const secureClient = new MongoClient(connectionString, {\n autoEncryption: {\n keyVaultNamespace,\n kmsProviders,\n schemaMap: patientSchema,\n extraOptions: extraOptions,\n tlsOptions,\n },\n});","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> secureClient <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(<!-- -->connectionString<!-- -->, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">autoEncryption</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->keyVaultNamespace<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->kmsProviders<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaMap</span>: <!-- -->patientSchema<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: <!-- -->extraOptions<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->tlsOptions<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-212-menu" aria-describedby="select-212-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-213" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rac:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rac:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rac:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rac:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_emcxgxcok" class="leafygreen-ui-38lglc" id="_6g7lfg10d" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fle_opts = AutoEncryptionOpts(\n kms_providers,\n key_vault_namespace,\n schema_map=patient_schema,\n kms_tls_options=tls_options,\n **extra_options\n)\nsecureClient = MongoClient(connection_string, auto_encryption_opts=fle_opts)","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">fle_opts = <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOpts</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_providers,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key_vault_namespace,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> schema_map=patient_schema,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kms_tls_options=tls_options,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> **extra_options</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">secureClient = <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connection_string, auto_encryption_opts=fle_opts)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-215-menu" aria-describedby="select-215-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-216" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rad:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rad:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rad:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rad:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
</ol>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Insert a Document with Encrypted Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#insert-a-document-with-encrypted-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="insert-a-document-with-encrypted-fields">
</div>
</a>
</h3>
<span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-kmip-insert">
</span>
<p class="leafygreen-ui-1kp3ins">
Use your CSFLE-enabled
<code class="leafygreen-ui-1l06pbn">
MongoClient
</code>
instance to insert a document with encrypted fields into the
<code class="leafygreen-ui-1l06pbn">
medicalRecords.patients
</code>
namespace using the following code
snippet:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-30">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_yaz5x01uf" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_qcpsgot0v" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_j7ub1rmcd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_0f6niffm4" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_uhhyru7tk" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_w39dcljrn" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_7y9q4q1i9" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_0zq2zuqk3" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_7ptl9n9ko" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_0u6wb8n72" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_y940bhxkx" class="leafygreen-ui-38lglc" id="_cv7rd5emj" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var sampleDocFields = new BsonDocument\n{\n { \"name\", \"Jon Doe\" },\n { \"ssn\", 145014000 },\n { \"bloodType\", \"AB-\" },\n {\n \"medicalRecords\", new BsonArray\n {\n new BsonDocument(\"weight\", 180),\n new BsonDocument(\"bloodPressure\", \"120/80\")\n }\n },\n {\n \"insurance\", new BsonDocument\n {\n { \"policyNumber\", 123142 },\n { \"provider\", \"MaestCare\" }\n }\n }\n};\n\n// Construct an auto-encrypting client\nvar secureCollection = secureClient.GetDatabase(db).GetCollection<bsondocument>(coll);\n\n// Insert a document into the collection\nsecureCollection.InsertOne(sampleDocFields);","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> sampleDocFields = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"ssn"</span>, <span class="lg-highlight-number">145014000</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"bloodType"</span>, <span class="lg-highlight-string">"AB-"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonArray</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"weight"</span>, <span class="lg-highlight-number">180</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span>(<span class="lg-highlight-string">"bloodPressure"</span>, <span class="lg-highlight-string">"120/80"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>, <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">BsonDocument</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"policyNumber"</span>, <span class="lg-highlight-number">123142</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <span class="lg-highlight-string">"provider"</span>, <span class="lg-highlight-string">"MaestCare"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">};</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Construct an auto-encrypting client</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> secureCollection = secureClient.<span class="lg-highlight-title lg-highlight-class">GetDatabase</span>(db).<span class="lg-highlight-property">GetCollection</span><<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>(coll);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Insert a document </span><span class="lg-highlight-comment">into the collection</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">secureCollection.<span class="lg-highlight-title lg-highlight-class">InsertOne</span>(sampleDocFields);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-218-menu" aria-describedby="select-218-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-219" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rae:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rae:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rae:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rae:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ekgku2gfo" class="leafygreen-ui-38lglc" id="_sf8xfd31z" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"test_patient := map[string]interface{}{\n\t\"name\": \"Jon Doe\",\n\t\"ssn\": 241014209,\n\t\"bloodType\": \"AB+\",\n\t\"medicalRecords\": []map[string]interface{}{{\n\t\t\"weight\": 180,\n\t\t\"bloodPressure\": \"120/80\",\n\t}},\n\t\"insurance\": map[string]interface{}{\n\t\t\"provider\": \"MaestCare\",\n\t\t\"policyNumber\": 123142,\n\t},\n}\nif _, err := secureClient.Database(dbName).Collection(collName).InsertOne(context.TODO(), test_patient); err != nil {\n\treturn fmt.Errorf(\"InsertOne error: %v\", err)\n}","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">test_patient <!-- -->:<!-- -->= map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>: <span class="lg-highlight-number">241014209</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodType"</span>: <span class="lg-highlight-string">"AB+"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>: []map[string]interface{}{{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"weight"</span>: <span class="lg-highlight-number">180</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodPressure"</span>: <span class="lg-highlight-string">"120/80"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>: map[string]interface{}{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"provider"</span>: <span class="lg-highlight-string">"MaestCare"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"policyNumber"</span>: <span class="lg-highlight-number">123142</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> _<!-- -->, <!-- -->err := secureClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(dbName).<span class="lg-highlight-title lg-highlight-class">Collection</span>(collName).<span class="lg-highlight-title lg-highlight-class">InsertOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), test_patient); err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> fmt.<span class="lg-highlight-title lg-highlight-class">Errorf</span>(<span class="lg-highlight-string">"InsertOne error: %v"</span>, err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-221-menu" aria-describedby="select-221-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-222" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:raf:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":raf:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":raf:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":raf:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Rather than creating a raw BSON document, you can pass a struct with
<code class="leafygreen-ui-1l06pbn">
bson
</code>
tags directly
to the driver for encoding.
</p>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_phd05pza3" class="leafygreen-ui-38lglc" id="_gwnhgswur" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ArrayList<document> medicalRecords = new ArrayList<>();\nmedicalRecords.add(new Document().append(\"weight\", \"180\"));\nmedicalRecords.add(new Document().append(\"bloodPressure\", \"120/80\"));\n\nDocument insurance = new Document()\n.append(\"policyNumber\", 123142)\n.append(\"provider\", \"MaestCare\");\n\nDocument patient = new Document()\n .append(\"name\", \"Jon Doe\")\n .append(\"ssn\", 241014209)\n .append(\"bloodType\", \"AB+\")\n .append(\"medicalRecords\", medicalRecords)\n .append(\"insurance\", insurance);\nmongoClientSecure.getDatabase(recordsDb).getCollection(recordsColl).insertOne(patient);","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">ArrayList</span><<span class="lg-highlight-title lg-highlight-class">Document</span>> medicalRecords = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ArrayList</span><>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx">medicalRecords.<span class="lg-highlight-title lg-highlight-function">add</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"weight"</span>, <span class="lg-highlight-string">"180"</span>));</td></tr><tr class=""><td class="leafygreen-ui-7razhx">medicalRecords.<span class="lg-highlight-title lg-highlight-function">add</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>().<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bloodPressure"</span>, <span class="lg-highlight-string">"120/80"</span>));</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Document</span> insurance = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">.<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"policyNumber"</span>, <span class="lg-highlight-number">123142</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">.<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"provider"</span>, <span class="lg-highlight-string">"MaestCare"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Document</span> patient = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Document</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"ssn"</span>, <span class="lg-highlight-number">241014209</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"bloodType"</span>, <span class="lg-highlight-string">"AB+"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"medicalRecords"</span>, medicalRecords)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">append</span>(<span class="lg-highlight-string">"insurance"</span>, insurance);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongoClientSecure.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(recordsDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(recordsColl).<span class="lg-highlight-title lg-highlight-function">insertOne</span>(patient);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-224-menu" aria-describedby="select-224-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-225" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rag:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rag:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rag:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rag:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_sza7mb8q0" class="" id="_3fgmef3qa" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"try {\n const writeResult = await secureClient\n .db(db)\n .collection(coll)\n .insertOne({\n name: \"Jon Doe\",\n ssn: 241014209,\n bloodType: \"AB+\",\n medicalRecords: [{ weight: 180, bloodPressure: \"120/80\" }],\n insurance: {\n policyNumber: 123142,\n provider: \"MaestCare\",\n },\n });\n} catch (writeError) {\n console.error(\"writeError occurred:\", writeError);\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">try</span> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">const</span> writeResult <!-- -->= <span class="lg-highlight-keyword">await</span> secureClient</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->db)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->coll)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">insertOne</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ssn</span>: <span class="lg-highlight-number">241014209</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bloodType</span>: <span class="lg-highlight-string">"AB+"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">medicalRecords</span>: <!-- -->[<!-- -->{ <span class="lg-highlight-attr">weight</span>: <span class="lg-highlight-number">180</span>, <span class="lg-highlight-attr">bloodPressure</span>: <span class="lg-highlight-string">"120/80"</span> }]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">insurance</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">policyNumber</span>: <span class="lg-highlight-number">123142</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">provider</span>: <span class="lg-highlight-string">"MaestCare"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->})<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} <span class="lg-highlight-keyword">catch</span> <!-- -->(<!-- -->writeError) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">error</span>(<span class="lg-highlight-string">"writeError occurred:"</span>, <!-- -->writeError)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-227-menu" aria-describedby="select-227-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-228" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rah:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rah:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rah:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rah:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ntxmtx9u5" class="leafygreen-ui-38lglc" id="_nmez16uo7" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"def insert_patient(\n collection, name, ssn, blood_type, medical_records, policy_number, provider\n):\n insurance = {\"policyNumber\": policy_number, \"provider\": provider}\n doc = {\n \"name\": name,\n \"ssn\": ssn,\n \"bloodType\": blood_type,\n \"medicalRecords\": medical_records,\n \"insurance\": insurance,\n }\n collection.insert_one(doc)\n\n\nmedical_record = [{\"weight\": 180, \"bloodPressure\": \"120/80\"}]\ninsert_patient(\n secureClient.medicalRecords.patients,\n \"Jon Doe\",\n 241014209,\n \"AB+\",\n medical_record,\n 123142,\n \"MaestCare\",\n)","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">def <span class="lg-highlight-title lg-highlight-function">insert_patient</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collection, name, ssn, blood_type, medical_records, policy_number, provider</td></tr><tr class=""><td class="leafygreen-ui-7razhx">):<!-- --></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> insurance = {<span class="lg-highlight-string">"policyNumber"</span>: policy_number, <span class="lg-highlight-string">"provider"</span>: provider}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> doc = {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span>: name,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ssn"</span>: ssn,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloodType"</span>: blood_type,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"medicalRecords"</span>: medical_records,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insurance"</span>: insurance,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collection.<span class="lg-highlight-title lg-highlight-function">insert_one</span>(doc)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">medical_record = [{<span class="lg-highlight-string">"weight"</span>: <span class="lg-highlight-number">180</span>, <span class="lg-highlight-string">"bloodPressure"</span>: <span class="lg-highlight-string">"120/80"</span>}]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">insert_patient</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> secureClient.<span class="lg-highlight-property">medicalRecords</span>.<span class="lg-highlight-property">patients</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Jon Doe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-number">241014209</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"AB+"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> medical_record,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-number">123142</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"MaestCare"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-230-menu" aria-describedby="select-230-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-231" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rai:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rai:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rai:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rai:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When you insert a document, your CSFLE-enabled client
encrypts the fields of your document such that it resembles the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": { \"$oid\": \"<_id of your document>\" },\n \"name\": \"Jon Doe\",\n \"ssn\": {\n \"$binary\": \"<cipher-text>\",\n \"$type\": \"6\"\n },\n \"bloodType\": {\n \"$binary\": \"<cipher-text>\",\n \"$type\": \"6\"\n },\n \"medicalRecords\": {\n \"$binary\": \"<cipher-text>\",\n \"$type\": \"6\"\n },\n \"insurance\": {\n \"provider\": \"MaestCare\",\n \"policyNumber\": {\n \"$binary\": \"<cipher-text>\",\n \"$type\": \"6\"\n }\n }\n}\n","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"_id"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"$oid"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"<_id of your document>"</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"name"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Jon Doe"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ssn"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"<cipher-text>"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"bloodType"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"<cipher-text>"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"medicalRecords"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"<cipher-text>"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"insurance"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"provider"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"MaestCare"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"policyNumber"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$binary"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"<cipher-text>"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"$type"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"6"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See: Complete Code
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-31">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_gqb7xkqv5" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_trp3tc8w0" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_gy0yhmjpu" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_npq9oytkb" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_dishn5ocv" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ukk0fv6m6" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_26fugb9sv" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_3x8hxjg3g" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_4upgelpoj" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_uj1yjgnq4" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_6o2zd0qyi" class="leafygreen-ui-38lglc" id="_bxfh0z2tz" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/kmip/reader/CSFLE/InsertEncryptedDocument.cs" rel="noopener noreferrer">
<span>
our Github repository
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_43lsrgm0j" class="leafygreen-ui-38lglc" id="_xc6l0m43i" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/kmip/reader/insert-encrypted-document.go" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_ggu17v3v8" class="leafygreen-ui-38lglc" id="_l8d94voa0" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/kmip/reader/src/main/java/com/mongodb/csfle/InsertEncryptedDocument.java" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_344r7dwqw" class="" id="_pzq34lme3" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/kmip/reader/insert_encrypted_document.js" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_yksa20vii" class="leafygreen-ui-38lglc" id="_sufe2r5w4" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/kmip/reader/insert_encrypted_document.py" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
5
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Retrieve Your Document with Encrypted Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-your-document-with-encrypted-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-your-document-with-encrypted-fields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Retrieve the document with encrypted fields you inserted in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-csfle-kmip-insert" target="_self">
<span>
Insert a Document with Encrypted Fields
</span>
</a>
step of this guide.
</p>
<p class="leafygreen-ui-1kp3ins">
To show the functionality of CSFLE, the following code snippet queries for
your document with a client configured for automatic CSFLE as well as
a client that is not configured for automatic CSFLE.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-33">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_93rydp1s5" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_l89qj79hm" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_z2j8pgsyt" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_f5oanz96q" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_rhrs2mjdv" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_9wrg1anp2" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_8tvt296yv" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_d6in3qeu7" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_z6l50fyic" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_fuy4gctk1" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_rgli8wnky" class="leafygreen-ui-38lglc" id="_0t8h5zb2w" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Console.WriteLine(\"Finding a document with regular (non-encrypted) client.\");\nvar filter = Builders<bsondocument>.Filter.Eq(\"name\", \"Jon Doe\");\nvar regularResult = regularCollection.Find(filter).Limit(1).ToList()[0];\nConsole.WriteLine($\"\\n{regularResult}\\n\");\n\nConsole.WriteLine(\"Finding a document with encrypted client\");\nvar ssnFilter = Builders<bsondocument>.Filter.Eq(\"name\", \"Jon Doe\");\nvar secureResult = secureCollection.Find(ssnFilter).Limit(1).First();\nConsole.WriteLine($\"\\n{secureResult}\\n\");","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> filter = <span class="lg-highlight-title lg-highlight-class">Builders</span><<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>.<span class="lg-highlight-property">Filter</span>.<span class="lg-highlight-title lg-highlight-class">Eq</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> regularResult = regularCollection.<span class="lg-highlight-title lg-highlight-class">Find</span>(filter).<span class="lg-highlight-title lg-highlight-class">Limit</span>(<span class="lg-highlight-number">1</span>).<span class="lg-highlight-title lg-highlight-class">ToList</span>()[<span class="lg-highlight-number">0</span>];</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>($<span class="lg-highlight-string">"</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">{regularResult}</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> ssnFilter = <span class="lg-highlight-title lg-highlight-class">Builders</span><<span class="lg-highlight-title lg-highlight-class">BsonDocument</span>>.<span class="lg-highlight-property">Filter</span>.<span class="lg-highlight-title lg-highlight-class">Eq</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> secureResult = secureCollection.<span class="lg-highlight-title lg-highlight-class">Find</span>(ssnFilter).<span class="lg-highlight-title lg-highlight-class">Limit</span>(<span class="lg-highlight-number">1</span>).<span class="lg-highlight-title lg-highlight-class">First</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Console</span>.<span class="lg-highlight-title lg-highlight-class">WriteLine</span>($<span class="lg-highlight-string">"</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">{secureResult}</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-233-menu" aria-describedby="select-233-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-234" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:raj:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":raj:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":raj:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":raj:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_v2ashxs6i" class="leafygreen-ui-38lglc" id="_kyac50seq" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fmt.Println(\"Finding a document with regular (non-encrypted) client.\")\nvar resultRegular bson.M\nerr = regularClient.Database(dbName).Collection(collName).FindOne(context.TODO(), bson.D{{\"name\", \"Jon Doe\"}}).Decode(&resultRegular)\nif err != nil {\n\tpanic(err)\n}\noutputRegular, err := json.MarshalIndent(resultRegular, \"\", \" \")\nif err != nil {\n\tpanic(err)\n}\nfmt.Printf(\"%s\\n\", outputRegular)\n\nfmt.Println(\"Finding a document with encrypted client\")\nvar resultSecure bson.M\nerr = secureClient.Database(dbName).Collection(collName).FindOne(context.TODO(), bson.D{{\"name\", \"Jon Doe\"}}).Decode(&resultSecure)\nif err != nil {\n\tpanic(err)\n}\noutputSecure, err := json.MarshalIndent(resultSecure, \"\", \" \")\nif err != nil {\n\tpanic(err)\n}\nfmt.Printf(\"%s\\n\", outputSecure)","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">fmt.<span class="lg-highlight-title lg-highlight-class">Println</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> resultRegular bson.<span class="lg-highlight-property">M</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">err = regularClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(dbName).<span class="lg-highlight-title lg-highlight-class">Collection</span>(collName).<span class="lg-highlight-title lg-highlight-class">FindOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), bson.<span class="lg-highlight-property">D</span>{{<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>}}).<span class="lg-highlight-title lg-highlight-class">Decode</span>(&resultRegular)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">outputRegular<!-- -->, <!-- -->err := json.<span class="lg-highlight-title lg-highlight-class">MarshalIndent</span>(resultRegular, <span class="lg-highlight-string">""</span>, <span class="lg-highlight-string">" "</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">fmt.<span class="lg-highlight-title lg-highlight-class">Printf</span>(<span class="lg-highlight-string">"%s</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, outputRegular)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">fmt.<span class="lg-highlight-title lg-highlight-class">Println</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> resultSecure bson.<span class="lg-highlight-property">M</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">err = secureClient.<span class="lg-highlight-title lg-highlight-class">Database</span>(dbName).<span class="lg-highlight-title lg-highlight-class">Collection</span>(collName).<span class="lg-highlight-title lg-highlight-class">FindOne</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), bson.<span class="lg-highlight-property">D</span>{{<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>}}).<span class="lg-highlight-title lg-highlight-class">Decode</span>(&resultSecure)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">outputSecure<!-- -->, <!-- -->err := json.<span class="lg-highlight-title lg-highlight-class">MarshalIndent</span>(resultSecure, <span class="lg-highlight-string">""</span>, <span class="lg-highlight-string">" "</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">if</span> err != nil {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">panic</span>(err)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">fmt.<span class="lg-highlight-title lg-highlight-class">Printf</span>(<span class="lg-highlight-string">"%s</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">"</span>, outputSecure)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-236-menu" aria-describedby="select-236-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-237" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rak:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rak:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rak:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rak:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_urofogy62" class="leafygreen-ui-38lglc" id="_j2jpri0gt" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"System.out.println(\"Finding a document with regular (non-encrypted) client.\");\nDocument docRegular = mongoClientRegular.getDatabase(recordsDb).getCollection(recordsColl).find(eq(\"name\", \"Jon Doe\")).first();\nSystem.out.println(docRegular.toJson());\n\nSystem.out.println(\"Finding a document with encrypted client\");\nDocument docSecure = mongoClientSecure.getDatabase(recordsDb).getCollection(recordsColl).find(eq(\"name\", \"Jon Doe\")).first();\nSystem.out.println(docSecure.toJson());","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Document</span> docRegular = mongoClientRegular.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(recordsDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(recordsColl).<span class="lg-highlight-title lg-highlight-function">find</span>(<span class="lg-highlight-title lg-highlight-function">eq</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>)).<span class="lg-highlight-title lg-highlight-function">first</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(docRegular.<span class="lg-highlight-title lg-highlight-function">toJson</span>());</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>);</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">Document</span> docSecure = mongoClientSecure.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(recordsDb).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(recordsColl).<span class="lg-highlight-title lg-highlight-function">find</span>(<span class="lg-highlight-title lg-highlight-function">eq</span>(<span class="lg-highlight-string">"name"</span>, <span class="lg-highlight-string">"Jon Doe"</span>)).<span class="lg-highlight-title lg-highlight-function">first</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">System</span>.<span class="lg-highlight-property">out</span>.<span class="lg-highlight-title lg-highlight-function">println</span>(docSecure.<span class="lg-highlight-title lg-highlight-function">toJson</span>());</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-239-menu" aria-describedby="select-239-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-240" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ral:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ral:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ral:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ral:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_o56n8woqp" class="" id="_zailbyvrv" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"console.log(\"Finding a document with regular (non-encrypted) client.\");\nconsole.log(\n await regularClient.db(db).collection(coll).findOne({ name: /Jon/ })\n);\n\nconsole.log(\"Finding a document with encrypted client\");\nconsole.log(\n await secureClient.db(db).collection(coll).findOne({ name: /Jon/ })\n);","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">await</span> regularClient.<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->db).<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->coll).<span class="lg-highlight-title lg-highlight-function">findOne</span>(<!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-regexp">/Jon/</span> <!-- -->})</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-variable lg-highlight-language">console</span>.<span class="lg-highlight-title lg-highlight-function">log</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">await</span> secureClient.<span class="lg-highlight-title lg-highlight-function">db</span>(<!-- -->db).<span class="lg-highlight-title lg-highlight-function">collection</span>(<!-- -->coll).<span class="lg-highlight-title lg-highlight-function">findOne</span>(<!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-regexp">/Jon/</span> <!-- -->})</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-242-menu" aria-describedby="select-242-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-243" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ram:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ram:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ram:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ram:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_nchsqqrg7" class="leafygreen-ui-38lglc" id="_ppmvdx1xr" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"print(\"Finding a document with regular (non-encrypted) client.\")\nresult = regularClient.medicalRecords.patients.find_one({\"name\": \"Jon Doe\"})\npprint.pprint(result)\n\nprint(\"Finding a document with encrypted client\")\npprint.pprint(secureClient.medicalRecords.patients.find_one({\"name\": \"Jon Doe\"}))","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">print</span>(<span class="lg-highlight-string">"Finding a document with regular (non-encrypted) client."</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">result = regularClient.<span class="lg-highlight-property">medicalRecords</span>.<span class="lg-highlight-property">patients</span>.<span class="lg-highlight-title lg-highlight-function">find_one</span>({<span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"Jon Doe"</span>})</td></tr><tr class=""><td class="leafygreen-ui-7razhx">pprint.<span class="lg-highlight-title lg-highlight-function">pprint</span>(result)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">print</span>(<span class="lg-highlight-string">"Finding a document with encrypted client"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">pprint.<span class="lg-highlight-title lg-highlight-function">pprint</span>(secureClient.<span class="lg-highlight-property">medicalRecords</span>.<span class="lg-highlight-property">patients</span>.<span class="lg-highlight-title lg-highlight-function">find_one</span>({<span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"Jon Doe"</span>}))</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-245-menu" aria-describedby="select-245-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-246" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ran:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ran:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ran:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ran:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The output of the preceding code snippet should look like this:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Finding a document with regular (non-encrypted) client.\n\n{\n _id: new ObjectId(\"629a452e0861b3130887103a\"),\n name: 'Jon Doe',\n ssn: new Binary(Buffer.from(\"0217482732d8014cdd9ffdd6e2966e5e7910c20697e5f4fa95710aafc9153f0a3dc769c8a132a604b468732ff1f4d8349ded3244b59cbfb41444a210f28b21ea1b6c737508d9d30e8baa30c1d8070c4d5e26\", \"hex\"), 6),\n bloodType: new Binary(Buffer.from(\"0217482732d8014cdd9ffdd6e2966e5e79022e238536dfd8caadb4d7751ac940e0f195addd7e5c67b61022d02faa90283ab69e02303c7e4001d1996128428bf037dea8bbf59fbb20c583cbcff2bf3e2519b4\", \"hex\"), 6),\n 'key-id': 'demo-data-key',\n medicalRecords: new Binary(Buffer.from(\"0217482732d8014cdd9ffdd6e2966e5e790405163a3207cff175455106f57eef14e5610c49a99bcbd14a7db9c5284e45e3ee30c149354015f941440bf54725d6492fb3b8704bc7c411cff6c868e4e13c58233c3d5ed9593eca4e4d027d76d3705b6d1f3b3c9e2ceee195fd944b553eb27eee69e5e67c338f146f8445995664980bf0\", \"hex\"), 6),\n insurance: {\n policyNumber: new Binary(Buffer.from(\"0217482732d8014cdd9ffdd6e2966e5e79108decd85c05be3fec099e015f9d26d9234605dc959cc1a19b63072f7ffda99db38c7b487de0572a03b2139ac3ee163bcc40c8508f366ce92a5dd36e38b3c742f7\", \"hex\"), 6),\n provider: 'MaestCare'\n }\n}\n\nFinding a document with encrypted client\n\n{\n _id: new ObjectId(\"629a452e0861b3130887103a\"),\n name: 'Jon Doe',\n ssn: 241014209,\n bloodType: 'AB+',\n 'key-id': 'demo-data-key',\n medicalRecords: [ { weight: 180, bloodPressure: '120/80' } ],\n insurance: { policyNumber: 123142, provider: 'MaestCare' }\n}\n","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">Finding a document with regular (non-encrypted) client.</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _id<span class="lg-highlight-punctuation">:</span> new ObjectId(<span class="lg-highlight-string">"629a452e0861b3130887103a"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> name<span class="lg-highlight-punctuation">:</span> 'Jon Doe'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ssn<span class="lg-highlight-punctuation">:</span> new Binary(Buffer.from(<span class="lg-highlight-string">"0217482732d8014cdd9ffdd6e2966e5e7910c20697e5f4fa95710aafc9153f0a3dc769c8a132a604b468732ff1f4d8349ded3244b59cbfb41444a210f28b21ea1b6c737508d9d30e8baa30c1d8070c4d5e26"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"hex"</span>)<span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">6</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bloodType<span class="lg-highlight-punctuation">:</span> new Binary(Buffer.from(<span class="lg-highlight-string">"0217482732d8014cdd9ffdd6e2966e5e79022e238536dfd8caadb4d7751ac940e0f195addd7e5c67b61022d02faa90283ab69e02303c7e4001d1996128428bf037dea8bbf59fbb20c583cbcff2bf3e2519b4"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"hex"</span>)<span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">6</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> 'key-id'<span class="lg-highlight-punctuation">:</span> 'demo-data-key'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> medicalRecords<span class="lg-highlight-punctuation">:</span> new Binary(Buffer.from(<span class="lg-highlight-string">"0217482732d8014cdd9ffdd6e2966e5e790405163a3207cff175455106f57eef14e5610c49a99bcbd14a7db9c5284e45e3ee30c149354015f941440bf54725d6492fb3b8704bc7c411cff6c868e4e13c58233c3d5ed9593eca4e4d027d76d3705b6d1f3b3c9e2ceee195fd944b553eb27eee69e5e67c338f146f8445995664980bf0"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"hex"</span>)<span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">6</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> insurance<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> policyNumber<span class="lg-highlight-punctuation">:</span> new Binary(Buffer.from(<span class="lg-highlight-string">"0217482732d8014cdd9ffdd6e2966e5e79108decd85c05be3fec099e015f9d26d9234605dc959cc1a19b63072f7ffda99db38c7b487de0572a03b2139ac3ee163bcc40c8508f366ce92a5dd36e38b3c742f7"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"hex"</span>)<span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">6</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> provider<span class="lg-highlight-punctuation">:</span> 'MaestCare'</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">Finding a document with encrypted client</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _id<span class="lg-highlight-punctuation">:</span> new ObjectId(<span class="lg-highlight-string">"629a452e0861b3130887103a"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> name<span class="lg-highlight-punctuation">:</span> 'Jon Doe'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ssn<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">241014209</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bloodType<span class="lg-highlight-punctuation">:</span> 'AB+'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> 'key-id'<span class="lg-highlight-punctuation">:</span> 'demo-data-key'<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> medicalRecords<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span> <span class="lg-highlight-punctuation">{</span> weight<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">180</span><span class="lg-highlight-punctuation">,</span> bloodPressure<span class="lg-highlight-punctuation">:</span> '<span class="lg-highlight-number">120</span>/<span class="lg-highlight-number">80</span>' <span class="lg-highlight-punctuation">}</span> <span class="lg-highlight-punctuation">]</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> insurance<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> policyNumber<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">123142</span><span class="lg-highlight-punctuation">,</span> provider<span class="lg-highlight-punctuation">:</span> 'MaestCare' <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See: Complete Code
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-34">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_0l1now2wg" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_2t7ytzjfn" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_jhqitzlnw" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_qjr29pj51" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_isutdz6qn" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_grwkppe24" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_487zx5izh" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_ig7f58wkd" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_1rm73wd4l" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_u7z1jr1h4" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_5tubpup7z" class="leafygreen-ui-38lglc" id="_i8yu2nvvq" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/dotnet/kmip/reader/CSFLE/InsertEncryptedDocument.cs" rel="noopener noreferrer">
<span>
our Github repository
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_d4rqz1qce" class="leafygreen-ui-38lglc" id="_zr9ukrfjz" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/go/kmip/reader/insert-encrypted-document.go" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_2ioqftmpg" class="leafygreen-ui-38lglc" id="_ole1rhpma" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/java/kmip/reader/src/main/java/com/mongodb/csfle/InsertEncryptedDocument.java" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_9q6xw71r1" class="" id="_mjracvxh6" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/node/kmip/reader/insert_encrypted_document.js" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_vv0ck4kfx" class="leafygreen-ui-38lglc" id="_h9uldy58h" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To view the complete code for inserting a document with encrypted fields, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/docs/tree/master/source/includes/generated/in-use-encryption/csfle/python/kmip/reader/insert_encrypted_document.py" rel="noopener noreferrer">
<span>
our Github repository
<!-- -->
.
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To learn how CSFLE works, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/#std-label-csfle-fundamentals">
Fundamentals
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about the topics mentioned in this guide, see the
following links:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Learn more about CSFLE components on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/#std-label-csfle-reference">
Reference
</a>
page.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Learn how Customer Master Keys and Data Encryption Keys work on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults">
Encryption Keys and Key Vaults
</a>
page.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
See how KMS Providers manage your CSFLE keys on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers">
KMS Providers
</a>
page.
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/data-modeling/design-patterns/data-versioning/schema-versioning/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Maintain Different Schema Versions
<a class="headerlink leafygreen-ui-1kepx47" href="#maintain-different-schema-versions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="maintain-different-schema-versions">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#about-this-task" target="_self">
<span>
About this Task
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#before-you-begin" target="_self">
<span>
Before you Begin
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#steps" target="_self">
<span>
Steps
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#add-a-schemaversion-field-to-the-collection" target="_self">
<span>
Add a schemaVersion field to the collection
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#insert-a-document-with-an-updated-schema" target="_self">
<span>
Insert a document with an updated schema
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#next-steps" target="_self">
<span>
Next Steps
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#query-the-collection" target="_self">
<span>
Query the Collection
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#update-a-document-in-the-collection" target="_self">
<span>
Update a Document in the Collection
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Your application's schema requirements may change over time. For
example, when new services become available, you may need to add new
fields to your documents. MongoDB's flexible data model means that you
can use a non-uniform document structure throughout your collection, and
you can retain your older document structure alongside the updated
schema.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<strong>
Schema Versioning Pattern
</strong>
lets you have different versions of
your schema in the same collection, which avoids large-scale schema
migrations when requirements change.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
About this Task
<a class="headerlink leafygreen-ui-1kepx47" href="#about-this-task" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="about-this-task">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If you have a field that appears at different levels in your documents,
the Schema Versioning Pattern may affect your indexes. For example, if
you store the same field as both a top-level field and as an embedded
field in different documents, you may need multiple indexes to support
queries on that field.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Before you Begin
<a class="headerlink leafygreen-ui-1kepx47" href="#before-you-begin" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="before-you-begin">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In the following example, an online store uses a collection to track
customer contact information. At first, the collection only contains
home and work phone numbers. Over time, new contact methods are added
and some older methods aren't needed.
</p>
<p class="leafygreen-ui-1kp3ins">
Insert the sample document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.contacts.insertOne(\n {\n _id: 1,\n name: \"Taylor\",\n home: \"209-555-7788\",\n work: \"503-555-0110\"\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">contacts</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Taylor"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">home</span>: <span class="lg-highlight-string">"209-555-7788"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">work</span>: <span class="lg-highlight-string">"503-555-0110"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Steps
<a class="headerlink leafygreen-ui-1kepx47" href="#steps" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="steps">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following procedure sets the initial schema version for the
collection, then inserts a new document with a different schema.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"To differentiate between different schemas in the collection, add\na schemaVersion field.The following command adds a schemaVersion field with the\nvalue 1 to the documents with the initial schema:","name":"Add a schemaVersion field to the collection"},{"@type":"HowToStep","text":"In the updated schema, customers can link their social media\naccounts. Insert a document that accounts for the new requirements\nand has a schemaVersion of 2:","name":"Insert a document with an updated schema"}],"name":"Steps","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Add a schemaVersion field to the collection
<a class="headerlink leafygreen-ui-1kepx47" href="#add-a-schemaversion-field-to-the-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="add-a-schemaversion-field-to-the-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To differentiate between different schemas in the collection, add
a
<code class="leafygreen-ui-1l06pbn">
schemaVersion
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
The following command adds a
<code class="leafygreen-ui-1l06pbn">
schemaVersion
</code>
field with the
value
<code class="leafygreen-ui-1l06pbn">
1
</code>
to the documents with the initial schema:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.contacts.updateMany(\n { },\n {\n $set: { schemaVersion: 1 }\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">contacts</span>.<span class="lg-highlight-title lg-highlight-function">updateMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">schemaVersion</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Insert a document with an updated schema
<a class="headerlink leafygreen-ui-1kepx47" href="#insert-a-document-with-an-updated-schema" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="insert-a-document-with-an-updated-schema">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
In the updated schema, customers can link their social media
accounts. Insert a document that accounts for the new requirements
and has a
<code class="leafygreen-ui-1l06pbn">
schemaVersion
</code>
of
<code class="leafygreen-ui-1l06pbn">
2
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.contacts.insertOne(\n {\n _id: 2,\n schemaVersion: 2,\n name: \"Cameron\",\n contactInfo: {\n cell: \"903-555-1122\",\n work: \"670-555-7878\",\n instagram: \"@camcam9090\",\n linkedIn: \"CameronSmith123\"\n }\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">contacts</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaVersion</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Cameron"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">contactInfo</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cell</span>: <span class="lg-highlight-string">"903-555-1122"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">work</span>: <span class="lg-highlight-string">"670-555-7878"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">instagram</span>: <span class="lg-highlight-string">"@camcam9090"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">linkedIn</span>: <span class="lg-highlight-string">"CameronSmith123"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Next Steps
<a class="headerlink leafygreen-ui-1kepx47" href="#next-steps" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="next-steps">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
After you implement the Schema Versioning Pattern, you need to modify
how your application queries and updates data.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query the Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#query-the-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="query-the-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Now that there are two different schemas in the
<code class="leafygreen-ui-1l06pbn">
contacts
</code>
collection,
your query must check all possible locations for a field value depending
on the document's schema version.
</p>
<p class="leafygreen-ui-1kp3ins">
The following query searches based on the customer's
<code class="leafygreen-ui-1l06pbn">
work
</code>
number. The query checks both possible locations for the
<code class="leafygreen-ui-1l06pbn">
work
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.contacts.find(\n {\n $or: [\n {\n work: \"503-555-0110\"\n },\n {\n \"contactInfo.work\": \"503-555-0110\"\n }\n ]\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">contacts</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$or</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">work</span>: <span class="lg-highlight-string">"503-555-0110"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"contactInfo.work"</span>: <span class="lg-highlight-string">"503-555-0110"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: 1,\n name: 'Taylor',\n home: '209-555-7788',\n work: '503-555-0110',\n schemaVersion: 1\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'Taylor'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">home</span>: <span class="lg-highlight-string">'209-555-7788'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">work</span>: <span class="lg-highlight-string">'503-555-0110'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaVersion</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update a Document in the Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#update-a-document-in-the-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-a-document-in-the-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Similar to inserting data, when you update a collection, your
application must check all possible locations for the field to be
updated. When you update data, you can use the
<code class="leafygreen-ui-1l06pbn">
schemaVersion
</code>
field
to determine the field to update.
</p>
<p class="leafygreen-ui-1kp3ins">
To update the
<code class="leafygreen-ui-1l06pbn">
work
</code>
phone number for the user with
<code class="leafygreen-ui-1l06pbn">
_id: 2
</code>
, run
this command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.contacts.updateOne(\n { _id: 2 },\n [\n {\n $set: {\n \"work\": {\n $cond: {\n if: { $eq: [ \"$schemaVersion\", 1 ] },\n then: \"999-999-9999\",\n else: null\n }\n },\n \"contactInfo.work\": {\n $cond: {\n if: { $eq: [ \"$schemaVersion\", 2 ] },\n then: \"999-999-9999\",\n else: null\n }\n }\n }\n }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">contacts</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$set</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"work"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$cond</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">if</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <span class="lg-highlight-string">"$schemaVersion"</span>, <span class="lg-highlight-number">1</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"999-999-9999"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">else</span>: <span class="lg-highlight-literal">null</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"contactInfo.work"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$cond</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">if</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <span class="lg-highlight-string">"$schemaVersion"</span>, <span class="lg-highlight-number">2</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"999-999-9999"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">else</span>: <span class="lg-highlight-literal">null</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In the previous example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the matched document's
<code class="leafygreen-ui-1l06pbn">
schemaVersion
</code>
is
<code class="leafygreen-ui-1l06pbn">
1
</code>
, then the
<code class="leafygreen-ui-1l06pbn">
work
</code>
field is set to the updated value.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the matched document's
<code class="leafygreen-ui-1l06pbn">
schemaVersion
</code>
is
<code class="leafygreen-ui-1l06pbn">
2
</code>
, then the
<code class="leafygreen-ui-1l06pbn">
contactInfo.work
</code>
field is set to the updated value.
</p>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/design-patterns/data-versioning/document-versioning/#std-label-design-patterns-document-versioning">
Keep a History of Document Versions
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/#std-label-schema-validation-overview">
Schema Validation
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/schema-design-process/#std-label-data-modeling-schema-design">
Schema Design Process
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$year (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-year--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-year--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$year
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-year" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-year">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns the year portion of a date.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-year" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$year
</code>
</span>
</a>
expression has the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
operator expression syntax
<!-- -->
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: <dateexpression> }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <<!-- -->dateExpression<!-- -->> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The argument can be:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
An
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-date">
Date
</a>
, a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-timestamp">
Timestamp
</a>
, or an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-object-id">
ObjectID
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A document with this format:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ date: <dateexpression>, timezone: <tzexpression> }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">date</span>: <<!-- -->dateExpression<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-attr">timezone</span>: <<!-- -->tzExpression<!-- -->> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:25%"/>
<col style="width:75%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
date
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The date to which the operator is applied.
<code class="leafygreen-ui-1l06pbn">
<dateExpression>
</code>
must be a valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-date">
Date
</a>
, a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-timestamp">
Timestamp
</a>
,
or an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-object-id">
ObjectID
<!-- -->
.
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The timezone of the operation result.
<code class="leafygreen-ui-1l06pbn">
<tzExpression>
</code>
must be a valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to a string formatted as either
an
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" rel="noopener noreferrer">
<span>
Olson Timezone Identifier
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
or a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/List_of_UTC_time_offsets" rel="noopener noreferrer">
<span>
UTC Offset
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
.
If no
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
is provided, the result is in UTC.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:30%"/>
<col style="width:70%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Format
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Examples
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
Olson Timezone Identifier
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"America/New_York\"\n\"Europe/London\"\n\"GMT\""}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">"America/New_York"</td></tr><tr class=""><td class="leafygreen-ui-7razhx">"Europe/London"</td></tr><tr class=""><td class="leafygreen-ui-7razhx">"GMT"</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
UTC Offset
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"+/-[hh]:[mm], e.g. \"+04:45\"\n+/-[hh][mm], e.g. \"-0530\"\n+/-[hh], e.g. \"+03\""}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">+/-[hh]:[mm], e.g. "+04:45"</td></tr><tr class=""><td class="leafygreen-ui-7razhx">+/-[hh][mm], e.g. "-0530"</td></tr><tr class=""><td class="leafygreen-ui-7razhx">+/-[hh], e.g. "+03"</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</li>
</ul>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:90%"/>
<col style="width:10%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Result
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: new Date(\"2016-01-01\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2016-01-01"</span>) }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2016
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: { date: new Date(\"Jan 7, 2003\") } }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"Jan 7, 2003"</span>) } }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2003
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: {\n date: new Date(\"August 14, 2011\"),\n timezone: \"America/Chicago\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"August 14, 2011"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/Chicago"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2011
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: ISODate(\"1998-11-07T00:00:00Z\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"1998-11-07T00:00:00Z"</span>) }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
1998
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: {\n date: ISODate(\"1998-11-07T00:00:00Z\"),\n timezone: \"-0400\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"1998-11-07T00:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"-0400"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
1998
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: \"March 28, 1976\" }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <span class="lg-highlight-string">"March 28, 1976"</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
error
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: Date(\"2016-01-01\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2016-01-01"</span>) }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
error
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $year: \"2009-04-09\" }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$year</span>: <span class="lg-highlight-string">"2009-04-09"</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
error
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
$year cannot take a string as an argument.
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider a
<code class="leafygreen-ui-1l06pbn">
sales
</code>
collection with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"item\" : \"abc\",\n \"price\" : 10,\n \"quantity\" : 2,\n \"date\" : ISODate(\"2014-01-01T08:15:39.736Z\")\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">10</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-01-01T08:15:39.736Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-year" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$year
</code>
</span>
</a>
and other
date operators to break down the
<code class="leafygreen-ui-1l06pbn">
date
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.aggregate(\n [\n {\n $project:\n {\n year: { $year: \"$date\" },\n month: { $month: \"$date\" },\n day: { $dayOfMonth: \"$date\" },\n hour: { $hour: \"$date\" },\n minutes: { $minute: \"$date\" },\n seconds: { $second: \"$date\" },\n milliseconds: { $millisecond: \"$date\" },\n dayOfYear: { $dayOfYear: \"$date\" },\n dayOfWeek: { $dayOfWeek: \"$date\" },\n week: { $week: \"$date\" }\n }\n }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">year</span>: <!-- -->{ <span class="lg-highlight-attr">$year</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">month</span>: <!-- -->{ <span class="lg-highlight-attr">$month</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">day</span>: <!-- -->{ <span class="lg-highlight-attr">$dayOfMonth</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">hour</span>: <!-- -->{ <span class="lg-highlight-attr">$hour</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">minutes</span>: <!-- -->{ <span class="lg-highlight-attr">$minute</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">seconds</span>: <!-- -->{ <span class="lg-highlight-attr">$second</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">milliseconds</span>: <!-- -->{ <span class="lg-highlight-attr">$millisecond</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dayOfYear</span>: <!-- -->{ <span class="lg-highlight-attr">$dayOfYear</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dayOfWeek</span>: <!-- -->{ <span class="lg-highlight-attr">$dayOfWeek</span>: <span class="lg-highlight-string">"$date"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">week</span>: <!-- -->{ <span class="lg-highlight-attr">$week</span>: <span class="lg-highlight-string">"$date"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following result:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"year\" : 2014,\n \"month\" : 1,\n \"day\" : 1,\n \"hour\" : 8,\n \"minutes\" : 15,\n \"seconds\" : 39,\n \"milliseconds\" : 736,\n \"dayOfYear\" : 1,\n \"dayOfWeek\" : 4,\n \"week\" : 0\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"year"</span> <!-- -->: <span class="lg-highlight-number">2014</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"month"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"day"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hour"</span> <!-- -->: <span class="lg-highlight-number">8</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"minutes"</span> <!-- -->: <span class="lg-highlight-number">15</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"seconds"</span> <!-- -->: <span class="lg-highlight-number">39</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"milliseconds"</span> <!-- -->: <span class="lg-highlight-number">736</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"dayOfYear"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"dayOfWeek"</span> <!-- -->: <span class="lg-highlight-number">4</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"week"</span> <!-- -->: <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/db.aggregate/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.aggregate()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.aggregate--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="db.aggregate--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
db.aggregate()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.aggregate" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-db.aggregate">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Runs a specified admin/diagnostic pipeline which does not require an
underlying collection. For aggregations on collection data, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
db.collection.aggregate()
</code>
.
</a>
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for database commands or language-specific drivers,
such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For the database command, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate">
<code class="leafygreen-ui-1l06pbn">
aggregate
</code>
</a>
command
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.aggregate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.aggregate()
</code>
</span>
</a>
method has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate( [ <pipeline> ], { <options> } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <<!-- -->pipeline<!-- -->> <!-- -->]<!-- -->, <!-- -->{ <<!-- -->options<!-- -->> <!-- -->} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
pipeline
</code>
parameter is an array of stages to execute. It
must start with a compatible stage that does not require an
underlying collection, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/currentOp/#mongodb-pipeline-pipe.-currentOp">
<code class="leafygreen-ui-1l06pbn">
$currentOp
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listLocalSessions/#mongodb-pipeline-pipe.-listLocalSessions">
<code class="leafygreen-ui-1l06pbn">
$listLocalSessions
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
options
</code>
document can contain the following fields and values:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
explain
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Specifies that the method should return
information on the processing of the pipeline.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#std-label-example-aggregate-method-explain-option">
Return Information on Aggregation Pipeline Operation
</a>
for an example.
</p>
<p class="leafygreen-ui-1kp3ins">
Not available in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
multi-document transactions
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
allowDiskUse
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Enables writing to temporary files. When set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, aggregation
operations can write data to the
<code class="file docutils literal">
<span class="pre">
_tmp
</span>
</code>
subdirectory in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath">
<code class="leafygreen-ui-1l06pbn">
dbPath
</code>
</a>
directory. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#std-label-example-aggregate-method-external-sort">
Interaction with
<code class="leafygreen-ui-1l06pbn">
allowDiskUseByDefault
</code>
</a>
for an example.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/#std-label-database-profiler">
profiler log messages
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
diagnostic log
messages
</a>
includes a
<code class="leafygreen-ui-1l06pbn">
usedDisk
</code>
indicator if any aggregation stage wrote data to temporary files due
to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline-limits/#std-label-agg-memory-restrictions">
memory restrictions
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
cursor
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. Specifies the
<em>
initial
</em>
batch size for the cursor. The value of the
<code class="leafygreen-ui-1l06pbn">
cursor
</code>
field is a document with the field
<code class="leafygreen-ui-1l06pbn">
batchSize
</code>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#std-label-example-aggregate-method-initial-batch-size">
Specify an Initial Batch Size
</a>
for syntax and example.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
non-negative integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Specifies a time limit in milliseconds for processing
operations on a cursor. If you do not specify a value for maxTimeMS,
operations will not time out. A value of
<code class="leafygreen-ui-1l06pbn">
0
</code>
explicitly
specifies the default unbounded behavior.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB terminates operations that exceed their allotted time limit
using the same mechanism as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.killOp/#mongodb-method-db.killOp">
<code class="leafygreen-ui-1l06pbn">
db.killOp()
</code>
</a>
. MongoDB only
terminates an operation at one of its designated
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-interrupt-point">
interrupt
points
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bypassDocumentValidation
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Applicable only if you specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
aggregation
stages.
</p>
<p class="leafygreen-ui-1kp3ins">
Enables
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
db.collection.aggregate()
</code>
</a>
to bypass document validation
during the operation. This lets you insert documents that do not
meet the validation requirements.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
readConcern
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-read-concern">
read concern
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
readConcern
</code>
option has the following syntax:
<code class="leafygreen-ui-1l06pbn">
readConcern: { level: <value> }
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
Possible read concern levels are:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
. This is the default read concern level for
read operations against the primary and secondaries.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
. Available for read operations against
the primary and secondaries.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
behaves the
same as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
against the primary and non-sharded
secondaries. The query returns the instance's most recent data.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
. Available for replica sets that use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger storage engine
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
. Available for read operations on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</a>
only.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For more formation on the read concern levels, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-read-concern-levels">
Read Concern Levels
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
stage cannot be used in conjunction with read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
. If you specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
read concern for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
db.collection.aggregate()
</code>
</a>
, you cannot include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
stage in the pipeline.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
stage cannot be used in conjunction with read
concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
. That is, if you specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
read concern for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
db.collection.aggregate()
</code>
</a>
, you cannot include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
stage in the pipeline.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
collation
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional.
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
</a>
to use for the operation.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
Collation
</a>
allows users to specify
language-specific rules for string comparison, such as rules for
lettercase and accent marks.
</p>
<p class="leafygreen-ui-1kp3ins">
The collation option has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"collation: {\n locale: <string>,\n caseLevel: <boolean>,\n caseFirst: <string>,\n strength: <int>,\n numericOrdering: <boolean>,\n alternate: <string>,\n maxVariable: <string>,\n backwards: <boolean>\n}"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">collation: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> locale: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseLevel: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseFirst: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> strength: <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> numericOrdering: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> alternate: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxVariable: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> backwards: <boolean></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When specifying collation, the
<code class="leafygreen-ui-1l06pbn">
locale
</code>
field is mandatory; all
other collation fields are optional. For descriptions of the fields,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation-document-fields">
Collation Document
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If the collation is unspecified but the collection has a
default collation (see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createCollection/#mongodb-method-db.createCollection">
<code class="leafygreen-ui-1l06pbn">
db.createCollection()
</code>
</a>
), the
operation uses the collation specified for the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
If no collation is specified for the collection or for the
operations, MongoDB uses the simple binary comparison used in prior
versions for string comparisons.
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot specify multiple collations for an operation. For
example, you cannot specify different collations per field, or if
performing a find with a sort, you cannot use one collation for the
find and another for the sort.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
hint
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string or document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The index to use for the aggregation. The index is on the initial
collection/view against which the aggregation is run.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify the index either by the index name or by the index
specification document.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
hint
</code>
does not apply to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup">
<code class="leafygreen-ui-1l06pbn">
$lookup
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/graphLookup/#mongodb-pipeline-pipe.-graphLookup">
<code class="leafygreen-ui-1l06pbn">
$graphLookup
</code>
</a>
stages.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
comment
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. Users can specify an arbitrary string to help trace the operation
through the database profiler, currentOp, and logs.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
writeConcern
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. A document that expresses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
to use with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
stage.
</p>
<p class="leafygreen-ui-1kp3ins">
Omit to use the default write concern with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
stage.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This method is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command has limited support in M0, M2, and M5 clusters.
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-admin-pipeline-currentOp">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Pipeline with
<code class="leafygreen-ui-1l06pbn">
$currentOp
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#pipeline-with--currentop" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="pipeline-with--currentop">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example runs a pipeline with two stages. The first stage
runs the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/currentOp/#mongodb-pipeline-pipe.-currentOp">
<code class="leafygreen-ui-1l06pbn">
$currentOp
</code>
</a>
operation and the second stage filters the
results of that operation.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use admin\ndb.aggregate( [ {\n $currentOp : { allUsers: true, idleConnections: true } }, {\n $match : { shard: \"shard01\" }\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use admin</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->$currentOp<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">allUsers</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">idleConnections</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->$match<!-- --> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">shard</span>: <span class="lg-highlight-string">"shard01"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$asin (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-asin--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-asin--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-asin" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-asin">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns the inverse sine (arc sine) of a value.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $asin: <expression> }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$asin</span>: <<!-- -->expression<!-- -->> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
takes any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to a number between
<code class="leafygreen-ui-1l06pbn">
-1
</code>
and
<code class="leafygreen-ui-1l06pbn">
1
</code>
, e.g.
<code class="leafygreen-ui-1l06pbn">
-1 <= value <= 1
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
returns values in radians. Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/radiansToDegrees/#mongodb-expression-exp.-radiansToDegrees">
<code class="leafygreen-ui-1l06pbn">
$radiansToDegrees
</code>
</a>
operator to convert the output value
from radians to degrees.
</p>
<p class="leafygreen-ui-1kp3ins">
By default
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
returns values as a
<code class="leafygreen-ui-1l06pbn">
double
</code>
.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
can also return values as a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self">
<span>
128-bit decimal
</span>
</a>
as long as the
<code class="leafygreen-ui-1l06pbn">
<expression>
</code>
resolves to a 128-bit decimal value.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
</dd>
</dl>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If the argument resolves to a value of
<code class="leafygreen-ui-1l06pbn">
null
</code>
or refers to a field
that is missing,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
. If the
argument resolves to
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
.
If the argument resolves to a value outside the bounds of
<code class="leafygreen-ui-1l06pbn">
[-1, 1]
</code>
inclusive,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
throws an error.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:85%"/>
<col style="width:15%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Results
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $asin: NaN }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $asin: null }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
null
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ $asin : Infinity}
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
or
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ $asin : -Infinity }
</code>
</p>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Throws an error message resembling the following formatted
output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"errmsg\" :\n \"Failed to optimize pipeline :: caused by :: cannot\n apply $asin to -inf, value must in [-1,1]\"","programmingLanguage":"Bash"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"errmsg"</span> :</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Failed to optimize pipeline :: caused by :: cannot</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> apply </span><span class="lg-highlight-variable lg-highlight-string">$asin</span><span class="lg-highlight-string"> to -inf, value must in [-1,1]"</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-7">
<div aria-label="Tabs to describe usage of degrees/radians" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_aqhmt0919" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_ilrhnja61" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Inverse Sine of Value in Degrees
</div>
</button>
<button aria-controls="_0sbdffk3l" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_9jo3jbj8z" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Inverse Sine of Value in Radians
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_e70z7w0wd" class="" id="_jpdvzky4n" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
trigonometry
</code>
collection contains a document that
stores three sides of a right-angle triangle:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"side_a\" : NumberDecimal(\"3\"),\n \"side_b\" : NumberDecimal(\"4\"),\n \"hypotenuse\" : NumberDecimal(\"5\")\n}","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"4"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
expression to calculate the angle opposite
to
<code class="leafygreen-ui-1l06pbn">
side_a
</code>
and add it to the input document using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
<code class="leafygreen-ui-1l06pbn">
$addFields
</code>
</a>
pipeline stage.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trigonometry.aggregate([\n {\n $addFields : {\n \"angle_a\" : {\n $radiansToDegrees : {\n $asin : {\n $divide : [ \"$side_a\", \"$hypotenuse\" ]\n }\n }\n }\n }\n }\n])","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.trigonometry.aggregate([</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$addFields</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$radiansToDegrees</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$asin</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$divide</span> : [ <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$side_a</span><span class="lg-highlight-string">"</span>, <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$hypotenuse</span><span class="lg-highlight-string">"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/radiansToDegrees/#mongodb-expression-exp.-radiansToDegrees">
<code class="leafygreen-ui-1l06pbn">
$radiansToDegrees
</code>
</a>
expression converts the
radian value returned by
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
to the equivalent
value in degrees.
</p>
<p class="leafygreen-ui-1kp3ins">
The command returns the following output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"side_a\" : NumberDecimal(\"3\"),\n \"side_b\" : NumberDecimal(\"4\"),\n \"hypotenuse\" : NumberDecimal(\"5\"),\n \"angle_a\" : NumberDecimal(\"36.86989764584402129685561255909341\")\n}","programmingLanguage":"Bash"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"4"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"36.86989764584402129685561255909341"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Since
<code class="leafygreen-ui-1l06pbn">
side_a
</code>
and
<code class="leafygreen-ui-1l06pbn">
hypotenuse
</code>
are stored as
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self">
<span>
128-bit decimals
</span>
</a>
, the output of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
is a 128-bit decimal.
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_gy4kubtg9" class="leafygreen-ui-38lglc" id="_if4eyrdg6" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
trigonometry
</code>
collection contains a document that
stores three sides of a right-angle triangle:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"side_a\" : NumberDecimal(\"3\"),\n \"side_b\" : NumberDecimal(\"4\"),\n \"hypotenuse\" : NumberDecimal(\"5\")\n}","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"4"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
expression to calculate the angle adjacent
to
<code class="leafygreen-ui-1l06pbn">
side_a
</code>
and add it to the input document using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
<code class="leafygreen-ui-1l06pbn">
$addFields
</code>
</a>
pipeline stage.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trigonometry.aggregate([\n {\n $addFields : {\n \"angle_a\" : {\n $asin : {\n $divide : [ \"$side_a\", \"$hypotenuse\" ]\n }\n }\n }\n }\n])","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.trigonometry.aggregate([</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$addFields</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$asin</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$divide</span> : [ <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$side_a</span><span class="lg-highlight-string">"</span>, <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$hypotenuse</span><span class="lg-highlight-string">"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The command returns the following output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"side_a\" : NumberDecimal(\"3\"),\n \"side_b\" : NumberDecimal(\"4\"),\n \"hypotenuse\" : NumberDecimal(\"5\"),\n \"angle_a\" : NumberDecimal(\"0.6435011087932843868028092287173226\")\n}","programmingLanguage":"Bash"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"4"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"0.6435011087932843868028092287173226"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Since
<code class="leafygreen-ui-1l06pbn">
side_a
</code>
and
<code class="leafygreen-ui-1l06pbn">
hypotenuse
</code>
are stored as
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self">
<span>
128-bit decimals
</span>
</a>
, the output of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-asin" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$asin
</code>
</span>
</a>
is a 128-bit decimal.
</p>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/wildcard-projection-signature/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Wildcard Index Signature
<a class="headerlink leafygreen-ui-1kepx47" href="#wildcard-index-signature" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="wildcard-index-signature">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#projection-signature-display" target="_self">
<span>
Projection Signature Display
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
option for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/#std-label-wildcard-index-core">
wildcard indexes
</a>
is included in the
<strong>
index
signature
</strong>
. The index signature is the combination of parameters that
uniquely identify the index. This means that you can create multiple
wildcard indexes with the same
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndexes/#std-label-key_patterns">
key pattern
</a>
as long
as the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
options do not contain the same fields.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Projection Signature Display
<a class="headerlink leafygreen-ui-1kepx47" href="#projection-signature-display" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="projection-signature-display">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.3, 6.0.5, and 5.0.16, the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
field stores the index projection in its submitted form. Earlier
versions of the server may have stored the projection in a normalized
form.
</p>
<p class="leafygreen-ui-1kp3ins">
The server uses the index the same way, but you may notice a difference
in the output of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/listIndexes/#mongodb-dbcommand-dbcmd.listIndexes">
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.getIndexes/#mongodb-method-db.collection.getIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.getIndexes()
</code>
</a>
commands.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider the following wildcard index on a
<code class="leafygreen-ui-1l06pbn">
books
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.createIndex(\n {\n \"$**\": 1\n },\n {\n wildcardProjection: {\n \"author.name\": 1,\n \"author.website\": 1\n },\n name: \"authorWildcard\"\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$**"</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wildcardProjection</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"author.name"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"author.website"</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"authorWildcard"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The index key pattern is
<code class="leafygreen-ui-1l06pbn">
"$**"
</code>
. You can create another wildcard
index with the same key pattern if you specify a different
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.createIndex(\n {\n \"$**\": 1\n },\n {\n wildcardProjection: {\n \"publisher.name\": 1\n },\n name: \"publisherWildcard\"\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$**"</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wildcardProjection</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"publisher.name"</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"publisherWildcard"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To view the created indexes, run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.getIndexes/#mongodb-method-db.collection.getIndexes">
<code class="leafygreen-ui-1l06pbn">
getIndexes()
</code>
</a>
method:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.getIndexes()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-title lg-highlight-function">getIndexes</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { v: 2, key: { _id: 1 }, name: '_id_' },\n {\n v: 2,\n key: { '$**': 1 },\n name: 'authorWildcard',\n wildcardProjection: { author: { website: true, name: true }, _id: false }\n },\n {\n v: 2,\n key: { '$**': 1 },\n name: 'publisherWildcard',\n wildcardProjection: { publisher: { name: true }, _id: false }\n }\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">v</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'_id_'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">v</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">'$**'</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'authorWildcard'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wildcardProjection</span>: <!-- -->{ <span class="lg-highlight-attr">author</span>: <!-- -->{ <span class="lg-highlight-attr">website</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-literal">true</span> }<!-- -->, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">v</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">'$**'</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'publisherWildcard'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wildcardProjection</span>: <!-- -->{ <span class="lg-highlight-attr">publisher</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-literal">true</span> }<!-- -->, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#std-label-createIndex-method-wildcard-option">
Options for
<code class="leafygreen-ui-1l06pbn">
wildcard
</code>
indexes
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions/#std-label-wildcard-index-restrictions">
Wildcard Index Restrictions
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/administration/replica-set-member-configuration/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Self-Managed Member Configuration Tutorials
<a class="headerlink leafygreen-ui-1kepx47" href="#self-managed-member-configuration-tutorials" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="self-managed-member-configuration-tutorials">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
The following tutorials provide information on configuring replica set
members to support specific operations, such as to provide dedicated
backups, to support reporting, or to act as a cold standby.
</p>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Avoid reconfiguring replica sets that contain members of different
MongoDB versions as validation rules may differ across MongoDB versions.
</p>
</div>
</div>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/adjust-replica-set-member-priority/">
Adjust Priority for a Self-Managed Replica Set Member
</a>
</dt>
<dd class="css-1ufxuu7">
Change the precedence given to a replica set members in an
election for primary.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-secondary-only-replica-set-member/">
Prevent a Self-Managed Secondary from Becoming Primary
</a>
</dt>
<dd class="css-1ufxuu7">
Make a secondary member ineligible for election as primary.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-a-hidden-replica-set-member/">
Configure a Hidden Self-Managed Replica Set Member
</a>
</dt>
<dd class="css-1ufxuu7">
Configure a secondary member to be invisible to applications in
order to support significantly different usage, such as a
dedicated backups.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-a-delayed-replica-set-member/">
Configure a Delayed Self-Managed Replica Set Member
</a>
</dt>
<dd class="css-1ufxuu7">
Configure a secondary member to keep a delayed copy of the data
set in order to provide a rolling backup.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-a-non-voting-replica-set-member/">
Configure a Non-Voting Self-Managed Replica Set Member
</a>
</dt>
<dd class="css-1ufxuu7">
Create a secondary member that keeps a copy of the data set but
does not vote in an election.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/convert-secondary-into-arbiter/">
Convert a Self-Managed Secondary to an Arbiter
</a>
</dt>
<dd class="css-1ufxuu7">
Convert a secondary to an arbiter.
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/data-modeling/design-antipatterns/unnecessary-indexes/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Remove Unnecessary Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#remove-unnecessary-indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="remove-unnecessary-indexes">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#about-this-task" target="_self">
<span>
About this Task
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#steps" target="_self">
<span>
Steps
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#evaluate-index-use" target="_self">
<span>
Evaluate index use
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#hide-indexes" target="_self">
<span>
Hide Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#drop-indexes" target="_self">
<span>
Drop Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Creating indexes for every query can lead to unnecessary indexes, which
can degrade database performance. Unnecessary indexes might be rarely
used, redundant due to coverage by another compound index, or not used
at all. To optimize database performance, it's important to minimize the
number of indexes you use. Identify and remove unnecessary indexes to
maintain efficient query execution and resource use.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
About this Task
<a class="headerlink leafygreen-ui-1kepx47" href="#about-this-task" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="about-this-task">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider the following
<code class="leafygreen-ui-1l06pbn">
courses
</code>
collection, where each document stores
information about a different school course.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// Biology course document\ndb.courses.insertOne(\n {\n _id: 1,\n course_name: \"Biology 101\",\n professor: \"Tate\",\n semester: \"Fall\",\n days: \"Monday, Friday\",\n time: \"12:00\",\n building: \"Olson\"\n }\n )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Biology course document</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">courses</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">course_name</span>: <span class="lg-highlight-string">"Biology 101"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">professor</span>: <span class="lg-highlight-string">"Tate"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">semester</span>: <span class="lg-highlight-string">"Fall"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">days</span>: <span class="lg-highlight-string">"Monday, Friday"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">time</span>: <span class="lg-highlight-string">"12:00"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">building</span>: <span class="lg-highlight-string">"Olson"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
courses
</code>
collection has an index for every field:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
_id
</code>
is indexed by default
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ course_name: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ professor: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ semester: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ building: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ days: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ time: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ day: 1, time: 1 }
</code>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Creating indexes for every field in a collection can lead to bloated
collections and negatively impact write performance.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Steps
<a class="headerlink leafygreen-ui-1kepx47" href="#steps" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="steps">
</div>
</a>
</h2>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"To determine which indexes are rarely used, use the $indexStats\naggregation stage:The operation returns the following:The building_1 index can be dropped because it is not used\nfor any queries, as indicated by its accesses count of zero.The { days: 1 } and { time: 1 } indexes can be dropped because\nthe compound index { day: 1, time: 1 }\ncovers time-related queries.You can also use MongoDB Atlas Performance Advisor\n(available for M10 clusters or higher) and MongoDB Compass to\ndetermine, hide, and drop unnecessary indexes.","name":"Evaluate index use"},{"@type":"HowToStep","text":"After you identify unnecessary indexes, you can use the\ndb.collection.hideIndex() method to hide the indexes and\nevaluate their impact on the database before you remove them.","name":"Hide Indexes"},{"@type":"HowToStep","text":"If you determine the indexes are unnecessary and have a negative impact\non performance, drop the indexes using the db.collection.dropIndexes()\nmethod.In this example, only the following indexes remain because they are the\nmost frequently used and help optimize queries:_id is indexed by default{ course_name: 1 }{ professor: 1 }{ semester: 1 }{ day: 1, time: 1 }","name":"Drop Indexes"}],"name":"Steps","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Evaluate index use
<a class="headerlink leafygreen-ui-1kepx47" href="#evaluate-index-use" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="evaluate-index-use">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To determine which indexes are rarely used, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/indexStats/#mongodb-pipeline-pipe.-indexStats">
<code class="leafygreen-ui-1l06pbn">
$indexStats
</code>
</a>
aggregation stage:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.courses.aggregate( [ { $indexStats: { } } ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">courses</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$indexStats</span>: <!-- -->{ <!-- -->} } ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n name: \"building_1\",\n key: { \"building\": 1 },\n host: \"M-C02FJ3BDML85:27017\",\n accesses: { \"ops\": \"Long('0')\", \"since\": \"ISODate('2024-06-24T17:35:00.000Z')\" },\n spec: { \"v\": 2, \"key\": { \"building\": 1 }, \"name\": \"building_1\" }\n },\n {\n name: \"day_1\",\n key: { \"day\": 1 },\n host: \"M-C02FJ3BDML85:27017\",\n accesses: { \"ops\": \"Long('1')\", \"since\": \"ISODate('2024-06-24T17:35:30.000Z')\" },\n spec: { \"v\": 2, \"key\": { \"day\": 1 }, \"name\": \"day_1\" }\n },\n {\n name: \"time_1\",\n key: { \"time\": 1 },\n host: \"M-C02FJ3BDML85:27017\",\n accesses: { \"ops\": \"Long('1')\", \"since\": \"ISODate('2024-06-24T17:36:00.000Z')\" },\n spec: { \"v\": 2, \"key\": { \"time\": 1 }, \"name\": \"time_1\" }\n },\n {\n name: \"day_1_time_1\",\n key: { \"day\": 1, \"time\": 1 },\n host: \"M-C02FJ3BDML85:27017\",\n accesses: { \"ops\": \"Long('110')\", \"since\": \"ISODate('2024-06-24T17:31:21.800Z')\" },\n spec: { \"v\": 2, \"key\": { \"day\": 1, \"time\": 1 }, \"name\": \"day_1_time_1\" }\n },\n {\n name: \"_id_\",\n key: { \"_id\": 1 },\n host: \"M-C02FJ3BDML85:27017\",\n accesses: { \"ops\": \"Long('150')\", \"since\": \"ISODate('2024-06-24T15:31:49.463Z')\" },\n spec: { \"v\": 2, \"key\": { \"_id\": 1 }, \"name\": \"_id_\" }\n },\n {\n name: \"course_name_1\",\n key: { \"course_name\": 1 },\n host: \"M-C02FJ3BDML85:27017\",\n accesses: { \"ops\": \"Long('120')\", \"since\": \"ISODate('2024-06-24T17:29:26.344Z')\" },\n spec: { \"v\": 2, \"key\": { \"course_name\": 1 }, \"name\": \"course_name_1\" }\n },\n ...\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"building_1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"building"</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">host</span>: <span class="lg-highlight-string">"M-C02FJ3BDML85:27017"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accesses</span>: <!-- -->{ <span class="lg-highlight-string">"ops"</span>: <span class="lg-highlight-string">"Long('0')"</span>, <span class="lg-highlight-string">"since"</span>: <span class="lg-highlight-string">"ISODate('2024-06-24T17:35:00.000Z')"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">spec</span>: <!-- -->{ <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"key"</span>: <!-- -->{ <span class="lg-highlight-string">"building"</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"building_1"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"day_1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"day"</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">host</span>: <span class="lg-highlight-string">"M-C02FJ3BDML85:27017"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accesses</span>: <!-- -->{ <span class="lg-highlight-string">"ops"</span>: <span class="lg-highlight-string">"Long('1')"</span>, <span class="lg-highlight-string">"since"</span>: <span class="lg-highlight-string">"ISODate('2024-06-24T17:35:30.000Z')"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">spec</span>: <!-- -->{ <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"key"</span>: <!-- -->{ <span class="lg-highlight-string">"day"</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"day_1"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"time_1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"time"</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">host</span>: <span class="lg-highlight-string">"M-C02FJ3BDML85:27017"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accesses</span>: <!-- -->{ <span class="lg-highlight-string">"ops"</span>: <span class="lg-highlight-string">"Long('1')"</span>, <span class="lg-highlight-string">"since"</span>: <span class="lg-highlight-string">"ISODate('2024-06-24T17:36:00.000Z')"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">spec</span>: <!-- -->{ <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"key"</span>: <!-- -->{ <span class="lg-highlight-string">"time"</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"time_1"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"day_1_time_1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"day"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"time"</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">host</span>: <span class="lg-highlight-string">"M-C02FJ3BDML85:27017"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accesses</span>: <!-- -->{ <span class="lg-highlight-string">"ops"</span>: <span class="lg-highlight-string">"Long('110')"</span>, <span class="lg-highlight-string">"since"</span>: <span class="lg-highlight-string">"ISODate('2024-06-24T17:31:21.800Z')"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">spec</span>: <!-- -->{ <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"key"</span>: <!-- -->{ <span class="lg-highlight-string">"day"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"time"</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"day_1_time_1"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"_id_"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">host</span>: <span class="lg-highlight-string">"M-C02FJ3BDML85:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accesses</span>: <!-- -->{ <span class="lg-highlight-string">"ops"</span>: <span class="lg-highlight-string">"Long('150')"</span>, <span class="lg-highlight-string">"since"</span>: <span class="lg-highlight-string">"ISODate('2024-06-24T15:31:49.463Z')"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">spec</span>: <!-- -->{ <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"key"</span>: <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"_id_"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"course_name_1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"course_name"</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">host</span>: <span class="lg-highlight-string">"M-C02FJ3BDML85:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accesses</span>: <!-- -->{ <span class="lg-highlight-string">"ops"</span>: <span class="lg-highlight-string">"Long('120')"</span>, <span class="lg-highlight-string">"since"</span>: <span class="lg-highlight-string">"ISODate('2024-06-24T17:29:26.344Z')"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">spec</span>: <!-- -->{ <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"key"</span>: <!-- -->{ <span class="lg-highlight-string">"course_name"</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"course_name_1"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
building_1
</code>
index can be dropped because it is not used
for any queries, as indicated by its
<code class="leafygreen-ui-1l06pbn">
accesses
</code>
count of zero.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
{ days: 1 }
</code>
and
<code class="leafygreen-ui-1l06pbn">
{ time: 1 }
</code>
indexes can be dropped because
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-index-type-compound">
compound index
</a>
<code class="leafygreen-ui-1l06pbn">
{ day: 1, time: 1 }
</code>
covers time-related queries.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You can also use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/performance-advisor/" target="_self">
<span>
MongoDB Atlas Performance Advisor
</span>
</a>
(available for M10 clusters or higher) and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/compass/current/" target="_self">
<span>
MongoDB Compass
</span>
</a>
to
determine, hide, and drop unnecessary indexes.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Hide Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#hide-indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="hide-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
After you identify unnecessary indexes, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.hideIndex/#mongodb-method-db.collection.hideIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.hideIndex()
</code>
</a>
method to hide the indexes and
evaluate their impact on the database before you remove them.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.courses.hideIndex( \"days_1\" )\ndb.courses.hideIndex( \"time_1\" )\ndb.courses.hideIndex( \"building_1\" )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">courses</span>.<span class="lg-highlight-title lg-highlight-function">hideIndex</span>( <span class="lg-highlight-string">"days_1"</span> )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">courses</span>.<span class="lg-highlight-title lg-highlight-function">hideIndex</span>( <span class="lg-highlight-string">"time_1"</span> )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">courses</span>.<span class="lg-highlight-title lg-highlight-function">hideIndex</span>( <span class="lg-highlight-string">"building_1"</span> )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Drop Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#drop-indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="drop-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you determine the indexes are unnecessary and have a negative impact
on performance, drop the indexes using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.dropIndexes/#mongodb-method-db.collection.dropIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.dropIndexes()
</code>
</a>
method.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.courses.dropIndexes( [ \"days_1\", \"time_1\", \"building_1\" ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">courses</span>.<span class="lg-highlight-title lg-highlight-function">dropIndexes</span>( <!-- -->[ <span class="lg-highlight-string">"days_1"</span>, <span class="lg-highlight-string">"time_1"</span>, <span class="lg-highlight-string">"building_1"</span> ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In this example, only the following indexes remain because they are the
most frequently used and help optimize queries:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
_id
</code>
is indexed by default
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ course_name: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ professor: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ semester: 1 }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ day: 1, time: 1 }
</code>
</p>
</li>
</ul>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/design-patterns/#std-label-schema-design-patterns">
Schema Design Patterns
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/performance-advisor/" target="_self">
<span>
MongoDB Atlas Performance Advisor
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/compass/current/indexes/" target="_self">
<span>
Manage Indexes
</span>
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text/text-index-versions/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Text Index Versions on Self-Managed Deployments
<a class="headerlink leafygreen-ui-1kepx47" href="#text-index-versions-on-self-managed-deployments" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="text-index-versions-on-self-managed-deployments">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#change-index-version" target="_self">
<span>
Change Index Version
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Text indexes are available in the following versions:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:25%"/>
<col style="width:75%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Text Index Version
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Version 3
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
MongoDB 3.2 introduces version 3 of text indexes. Version 3
is the default version for text indexes created in
MongoDB 3.2 and later.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Version 2
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
MongoDB 2.6 introduces version 2 of text indexes.
Version 2 is the default version for text indexes created
in MongoDB 2.6 to 3.0.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Version 1
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
MongoDB 2.4 introduces version 1 of text indexes.
MongoDB 2.4 only supports version 1.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Change Index Version
<a class="headerlink leafygreen-ui-1kepx47" href="#change-index-version" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="change-index-version">
</div>
</a>
</h2>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Always use the default index version when possible. Only override the
default version if required for compatibility reasons.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To override the default version and specify a different version for your
text index, set the
<code class="leafygreen-ui-1l06pbn">
textIndexVersion
</code>
option when you create an
index:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.<collection>.createIndex(\n { <field>: \"text\" },\n { \"textIndexVersion\": <version> }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<!-- --><<!-- -->collection<!-- -->><!-- -->.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <<!-- -->field<!-- -->><!-- -->: <span class="lg-highlight-string">"text"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"textIndexVersion"</span>: <<!-- -->version<!-- -->> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following command creates a version 2 text index on the
<code class="leafygreen-ui-1l06pbn">
content
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.test.createIndex(\n { \"content\": \"text\" },\n { \"textIndexVersion\": 2 }\n )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">test</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"content"</span>: <span class="lg-highlight-string">"text"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"textIndexVersion"</span>: <span class="lg-highlight-number">2</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$setIntersection (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-setintersection--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-setintersection--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-setIntersection" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-setIntersection">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Takes two or more arrays and returns an array that contains the
elements that appear in every input array.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $setIntersection: [ <array1>, <array2>, ... ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$setIntersection</span>: <!-- -->[ <<!-- -->array1<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->array2<!-- -->><!-- -->,<!-- --> <!-- -->...<!-- --> ] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The arguments can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
as long as they each resolve to an array.
For more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
performs set operation on arrays, treating arrays
as sets. If an array contains duplicate entries,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
ignores the duplicate entries.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
ignores the order of
the elements.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
filters out duplicates in its result to output an
array that contain only unique entries. The order of the elements in
the output array is unspecified.
</p>
<p class="leafygreen-ui-1kp3ins">
If no intersections are found (i.e. the input arrays contain no common
elements),
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
returns an empty array.
</p>
<p class="leafygreen-ui-1kp3ins">
If a set contains a nested array element,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
does
<em>
not
</em>
descend
into the nested array but evaluates the array at top-level.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:75%"/>
<col style="width:25%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Result
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $setIntersection: [ [ \"a\", \"b\", \"a\" ], [ \"b\", \"a\" ] ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$setIntersection</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"a"</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"a"</span> ] ] }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ \"b\", \"a\" ]","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[ <span class="lg-highlight-string">"b"</span>, <span class="lg-highlight-string">"a"</span> ]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $setIntersection: [ [ \"a\", \"b\" ], [ [ \"a\", \"b\" ] ] ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$setIntersection</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"b"</span> ]<!-- -->, <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"a"</span>, <span class="lg-highlight-string">"b"</span> ] ] ] }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ ]","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[ <!-- -->]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This section contains examples that show the use of
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
with collections.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Elements Array Example
<a class="headerlink leafygreen-ui-1kepx47" href="#elements-array-example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="elements-array-example">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Consider an
<code class="leafygreen-ui-1l06pbn">
flowers
</code>
collection with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.flowers.insertMany( [\n { \"_id\" : 1, \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ \"rose\", \"orchid\" ] },\n { \"_id\" : 2, \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ \"orchid\", \"rose\", \"orchid\" ] },\n { \"_id\" : 3, \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ \"rose\", \"orchid\", \"jasmine\" ] },\n { \"_id\" : 4, \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ \"jasmine\", \"rose\" ] },\n { \"_id\" : 5, \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ ] },\n { \"_id\" : 6, \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ [ \"rose\" ], [ \"orchid\" ] ] },\n { \"_id\" : 7, \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ [ \"rose\", \"orchid\" ] ] },\n { \"_id\" : 8, \"flowerFieldA\" : [ ], \"flowerFieldB\" : [ ] },\n { \"_id\" : 9, \"flowerFieldA\" : [ ], \"flowerFieldB\" : [ \"rose\" ] }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">flowers</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"orchid"</span>, <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span>, <span class="lg-highlight-string">"jasmine"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"jasmine"</span>, <span class="lg-highlight-string">"rose"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <!-- -->] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"rose"</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"orchid"</span> ] ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ] ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">8</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <!-- -->]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <!-- -->] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">9</span>, <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <!-- -->]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
operator to return an array of elements common to both the
<code class="leafygreen-ui-1l06pbn">
flowerFieldA
</code>
array and the
<code class="leafygreen-ui-1l06pbn">
flowerFieldB
</code>
array:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.flowers.aggregate(\n [\n { $project: { flowerFieldA: 1, flowerFieldB: 1, commonToBoth: { $setIntersection: [ \"$flowerFieldA\", \"$flowerFieldB\" ] }, _id: 0 } }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">flowers</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">flowerFieldA</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">flowerFieldB</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">commonToBoth</span>: <!-- -->{ <span class="lg-highlight-attr">$setIntersection</span>: <!-- -->[ <span class="lg-highlight-string">"$flowerFieldA"</span>, <span class="lg-highlight-string">"$flowerFieldB"</span> ] }<!-- -->, <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following results:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ \"rose\", \"orchid\" ], \"commonToBoth\" : [ \"orchid\", \"rose\" ] }\n{ \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ \"orchid\", \"rose\", \"orchid\" ], \"commonToBoth\" : [ \"orchid\", \"rose\" ] }\n{ \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ \"rose\", \"orchid\", \"jasmine\" ], \"commonToBoth\" : [ \"orchid\", \"rose\" ] }\n{ \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ \"jasmine\", \"rose\" ], \"commonToBoth\" : [ \"rose\" ] }\n{ \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ ], \"commonToBoth\" : [ ] }\n{ \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ [ \"rose\" ], [ \"orchid\" ] ], \"commonToBoth\" : [ ] }\n{ \"flowerFieldA\" : [ \"rose\", \"orchid\" ], \"flowerFieldB\" : [ [ \"rose\", \"orchid\" ] ], \"commonToBoth\" : [ ] }\n{ \"flowerFieldA\" : [ ], \"flowerFieldB\" : [ ], \"commonToBoth\" : [ ] }\n{ \"flowerFieldA\" : [ ], \"flowerFieldB\" : [ \"rose\" ], \"commonToBoth\" : [ ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"orchid"</span>, <span class="lg-highlight-string">"rose"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"orchid"</span>, <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"orchid"</span>, <span class="lg-highlight-string">"rose"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span>, <span class="lg-highlight-string">"jasmine"</span> ]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"orchid"</span>, <span class="lg-highlight-string">"rose"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"jasmine"</span>, <span class="lg-highlight-string">"rose"</span> ]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <!-- -->]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <!-- -->] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"rose"</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"orchid"</span> ] ]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <!-- -->] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"rose"</span>, <span class="lg-highlight-string">"orchid"</span> ] ]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <!-- -->] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <!-- -->]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <!-- -->]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <!-- -->] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"flowerFieldA"</span> <!-- -->: <!-- -->[ <!-- -->]<!-- -->, <span class="lg-highlight-string">"flowerFieldB"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"rose"</span> ]<!-- -->, <span class="lg-highlight-string">"commonToBoth"</span> <!-- -->: <!-- -->[ <!-- -->] }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-setIntersection-user-roles-system-variable-example">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Retrieve Documents for Roles Granted to the Current User
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-documents-for-roles-granted-to-the-current-user" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-documents-for-roles-granted-to-the-current-user">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, you can use the new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.USER_ROLES">
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
</a>
system variable to return user
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-roles">
roles
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The scenario in this section shows users with various roles who have
limited access to documents in a collection containing budget
information.
</p>
<p class="leafygreen-ui-1kp3ins">
The scenario shows one possible use of
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
. The
<code class="leafygreen-ui-1l06pbn">
budget
</code>
collection contains documents with a field named
<code class="leafygreen-ui-1l06pbn">
allowedRoles
</code>
. As
you'll see in the following scenario, you can write queries that compare
the user roles found in the
<code class="leafygreen-ui-1l06pbn">
allowedRoles
</code>
field with the roles
returned by the
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
system variable.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
For another
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
example scenario, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/create-view/#std-label-create-view-user-roles-system-variable-medical-example">
Retrieve Medical Information for Roles Granted to the Current User
</a>
. That
example doesn't store the user roles in the document fields, as is
done in the following example.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For the budget scenario in this section, perform the following steps to
create the roles, users, and
<code class="leafygreen-ui-1l06pbn">
budget
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Run:","name":"Create the roles"},{"@type":"HowToStep","text":"Create users named John and Jane with the required roles.\nReplace the test database with your database name.","name":"Create the users"},{"@type":"HowToStep","text":"Run:","name":"Create the collection"}],"name":"Retrieve Documents for Roles Granted to the Current User","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create the roles
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-roles" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-the-roles">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Run:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.createRole( { role: \"Marketing\", roles: [], privileges: [] } )\ndb.createRole( { role: \"Sales\", roles: [], privileges: [] } )\ndb.createRole( { role: \"Development\", roles: [], privileges: [] } )\ndb.createRole( { role: \"Operations\", roles: [], privileges: [] } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">createRole</span>( <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Marketing"</span>, <span class="lg-highlight-attr">roles</span>: <!-- -->[<!-- -->]<!-- -->, <span class="lg-highlight-attr">privileges</span>: <!-- -->[<!-- -->] } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">createRole</span>( <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Sales"</span>, <span class="lg-highlight-attr">roles</span>: <!-- -->[<!-- -->]<!-- -->, <span class="lg-highlight-attr">privileges</span>: <!-- -->[<!-- -->] } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">createRole</span>( <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Development"</span>, <span class="lg-highlight-attr">roles</span>: <!-- -->[<!-- -->]<!-- -->, <span class="lg-highlight-attr">privileges</span>: <!-- -->[<!-- -->] } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">createRole</span>( <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Operations"</span>, <span class="lg-highlight-attr">roles</span>: <!-- -->[<!-- -->]<!-- -->, <span class="lg-highlight-attr">privileges</span>: <!-- -->[<!-- -->] } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create the users
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-users" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-the-users">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Create users named
<code class="leafygreen-ui-1l06pbn">
John
</code>
and
<code class="leafygreen-ui-1l06pbn">
Jane
</code>
with the required roles.
Replace the
<code class="leafygreen-ui-1l06pbn">
test
</code>
database with your database name.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.createUser( {\n user: \"John\",\n pwd: \"jn008\",\n roles: [\n { role: \"Marketing\", db: \"test\" },\n { role: \"Development\", db: \"test\" },\n { role: \"Operations\", db: \"test\" },\n { role: \"read\", db: \"test\" }\n ]\n} )\n\ndb.createUser( {\n user: \"Jane\",\n pwd: \"je009\",\n roles: [\n { role: \"Sales\", db: \"test\" },\n { role: \"Operations\", db: \"test\" },\n { role: \"read\", db: \"test\" }\n ]\n} )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">createUser</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"John"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pwd</span>: <span class="lg-highlight-string">"jn008"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">roles</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Marketing"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"test"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Development"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"test"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Operations"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"test"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"read"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"test"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">createUser</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"Jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pwd</span>: <span class="lg-highlight-string">"je009"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">roles</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Sales"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"test"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"Operations"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"test"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"read"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"test"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create the collection
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-the-collection">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Run:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.budget.insertMany( [\n {\n _id: 0,\n allowedRoles: [ \"Marketing\" ],\n comment: \"For marketing team\",\n yearlyBudget: 15000\n },\n {\n _id: 1,\n allowedRoles: [ \"Sales\" ],\n comment: \"For sales team\",\n yearlyBudget: 17000,\n salesEventsBudget: 1000\n },\n {\n _id: 2,\n allowedRoles: [ \"Operations\" ],\n comment: \"For operations team\",\n yearlyBudget: 19000,\n cloudBudget: 12000\n },\n {\n _id: 3,\n allowedRoles: [ \"Development\" ],\n comment: \"For development team\",\n yearlyBudget: 27000\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">budget</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">"Marketing"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">"For marketing team"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">15000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">"Sales"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">"For sales team"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">17000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">salesEventsBudget</span>: <span class="lg-highlight-number">1000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">"Operations"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">"For operations team"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">19000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cloudBudget</span>: <span class="lg-highlight-number">12000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">"Development"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">"For development team"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">27000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Perform the following steps to retrieve the documents accessible to
<code class="leafygreen-ui-1l06pbn">
John
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Run:","name":"Log in as John"},{"@type":"HowToStep","text":"To use a system variable, add $$ to the start of the variable name.\nSpecify the USER_ROLES system variable as $$USER_ROLES.Run:The previous example returns the documents from the budget\ncollection that match at least one of the roles that the user who runs\nthe example has. To do that, the example uses\n$setIntersection to return documents where the\nintersection between the budget document allowedRoles field and\nthe set of user roles from $$USER_ROLES is not empty.","name":"Retrieve the documents"},{"@type":"HowToStep","text":"John has the Marketing, Operations, and Development\nroles, and sees these documents:","name":"Examine the documents"}],"name":"Retrieve Documents for Roles Granted to the Current User","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Log in as John
<a class="headerlink leafygreen-ui-1kepx47" href="#log-in-as-john" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="log-in-as-john">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Run:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.auth( \"John\", \"jn008\" )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">auth</span>( <span class="lg-highlight-string">"John"</span>, <span class="lg-highlight-string">"jn008"</span> )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Retrieve the documents
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-the-documents" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-the-documents">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
To use a system variable, add
<code class="leafygreen-ui-1l06pbn">
$$
</code>
to the start of the variable name.
Specify the
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
system variable as
<code class="leafygreen-ui-1l06pbn">
$$USER_ROLES
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Run:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.budget.aggregate( [ {\n $match: {\n $expr: {\n $not: {\n $eq: [ { $setIntersection: [ \"$allowedRoles\", \"$$USER_ROLES.role\" ] }, [] ]\n }\n }\n }\n} ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">budget</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$match</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$expr</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$not</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$setIntersection</span>: <!-- -->[ <span class="lg-highlight-string">"$allowedRoles"</span>, <span class="lg-highlight-string">"$$USER_ROLES.role"</span> ] }<!-- -->, <!-- -->[<!-- -->] ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The previous example returns the documents from the
<code class="leafygreen-ui-1l06pbn">
budget
</code>
collection that match at least one of the roles that the user who runs
the example has. To do that, the example uses
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-setIntersection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</span>
</a>
to return documents where the
intersection between the
<code class="leafygreen-ui-1l06pbn">
budget
</code>
document
<code class="leafygreen-ui-1l06pbn">
allowedRoles
</code>
field and
the set of user roles from
<code class="leafygreen-ui-1l06pbn">
$$USER_ROLES
</code>
is not empty.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Examine the documents
<a class="headerlink leafygreen-ui-1kepx47" href="#examine-the-documents" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examine-the-documents">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
John
</code>
has the
<code class="leafygreen-ui-1l06pbn">
Marketing
</code>
,
<code class="leafygreen-ui-1l06pbn">
Operations
</code>
, and
<code class="leafygreen-ui-1l06pbn">
Development
</code>
roles, and sees these documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: 0,\n allowedRoles: [ 'Marketing' ],\n comment: 'For marketing team',\n yearlyBudget: 15000\n },\n {\n _id: 2,\n allowedRoles: [ 'Operations' ],\n comment: 'For operations team',\n yearlyBudget: 19000,\n cloudBudget: 12000\n },\n {\n _id: 3,\n allowedRoles: [ 'Development' ],\n comment: 'For development team',\n yearlyBudget: 27000\n }\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">'Marketing'</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">'For marketing team'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">15000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">'Operations'</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">'For operations team'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">19000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cloudBudget</span>: <span class="lg-highlight-number">12000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">'Development'</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">'For development team'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">27000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Perform the following steps to retrieve the documents accessible to
<code class="leafygreen-ui-1l06pbn">
Jane
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Run:","name":"Log in as Jane"},{"@type":"HowToStep","text":"To use a system variable, add $$ to the start of the variable name.\nSpecify the USER_ROLES system variable as $$USER_ROLES.Run:","name":"Retrieve the documents"},{"@type":"HowToStep","text":"Jane has the Sales and Operations roles, and sees these\ndocuments:On a sharded cluster, a query can be run on a shard by another server\nnode on behalf of the user. In those queries, USER_ROLES is still\npopulated with the roles for the user.","name":"Examine the documents"}],"name":"Retrieve Documents for Roles Granted to the Current User","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Log in as Jane
<a class="headerlink leafygreen-ui-1kepx47" href="#log-in-as-jane" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="log-in-as-jane">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Run:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.auth( \"Jane\", \"je009\" )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">auth</span>( <span class="lg-highlight-string">"Jane"</span>, <span class="lg-highlight-string">"je009"</span> )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Retrieve the documents
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-the-documents-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-the-documents-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
To use a system variable, add
<code class="leafygreen-ui-1l06pbn">
$$
</code>
to the start of the variable name.
Specify the
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
system variable as
<code class="leafygreen-ui-1l06pbn">
$$USER_ROLES
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Run:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.budget.aggregate( [ {\n $match: {\n $expr: {\n $not: {\n $eq: [ { $setIntersection: [ \"$allowedRoles\", \"$$USER_ROLES.role\" ] }, [] ]\n }\n }\n }\n} ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">budget</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$match</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$expr</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$not</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$setIntersection</span>: <!-- -->[ <span class="lg-highlight-string">"$allowedRoles"</span>, <span class="lg-highlight-string">"$$USER_ROLES.role"</span> ] }<!-- -->, <!-- -->[<!-- -->] ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Examine the documents
<a class="headerlink leafygreen-ui-1kepx47" href="#examine-the-documents-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examine-the-documents-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Jane
</code>
has the
<code class="leafygreen-ui-1l06pbn">
Sales
</code>
and
<code class="leafygreen-ui-1l06pbn">
Operations
</code>
roles, and sees these
documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: 1,\n allowedRoles: [ 'Sales' ],\n comment: 'For sales team',\n yearlyBudget: 17000,\n salesEventsBudget: 1000\n },\n {\n _id: 2,\n allowedRoles: [ 'Operations' ],\n comment: 'For operations team',\n yearlyBudget: 19000,\n cloudBudget: 12000\n }\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">'Sales'</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">'For sales team'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">17000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">salesEventsBudget</span>: <span class="lg-highlight-number">1000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowedRoles</span>: <!-- -->[ <span class="lg-highlight-string">'Operations'</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">'For operations team'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearlyBudget</span>: <span class="lg-highlight-number">19000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cloudBudget</span>: <span class="lg-highlight-number">12000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
On a sharded cluster, a query can be run on a shard by another server
node on behalf of the user. In those queries,
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
is still
populated with the roles for the user.
</p>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/update/push/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$push
<a class="headerlink leafygreen-ui-1kepx47" href="#-push" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-push">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#modifiers" target="_self">
<span>
Modifiers
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="update">
<dt>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-update-up.-push" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-update-up.-push">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
operator appends a specified value to an array.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can use
<code class="leafygreen-ui-1l06pbn">
$push
</code>
for deployments hosted in the following
environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
operator has the form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $push: { <field1>: <value1>, ... } }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$push</span>: <!-- -->{ <<!-- -->field1<!-- -->><!-- -->: <<!-- -->value1<!-- -->><!-- -->,<!-- --> <!-- -->...<!-- --> } }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To specify a
<code class="leafygreen-ui-1l06pbn">
<field>
</code>
in an embedded document or in an array, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/document/#std-label-document-dot-notation">
dot notation
<!-- -->
.
</a>
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, update operators process document fields with
string-based names in lexicographic order. Fields with numeric names are
processed in numeric order. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/#std-label-update-operators-processing-order">
Update Operators Behavior
</a>
for details.
</p>
<p class="leafygreen-ui-1kp3ins">
If the field is absent in the document to update,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
adds
the array field with the value as its element.
</p>
<p class="leafygreen-ui-1kp3ins">
If the field is
<strong>
not
</strong>
an array, the operation will fail.
</p>
<p class="leafygreen-ui-1kp3ins">
If the value is an array,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
appends the whole array as a
<em>
single
</em>
element. To add each element of the value separately, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/each/#mongodb-update-up.-each">
<code class="leafygreen-ui-1l06pbn">
$each
</code>
</a>
modifier with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
. For an example, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-example-push-each" target="_self">
<span>
Append a Value to Arrays in Multiple Documents
</span>
</a>
. For a list of modifiers available for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-push-modifiers" target="_self">
<span>
Modifiers
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
no longer raises an
error when you use an update operator like
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
with an empty operand expression (
<code class="leafygreen-ui-1l06pbn">
{ }
</code>
). An empty update results
in no changes and no
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
entry is created (meaning that the
operation is a no-op).
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-push-modifiers">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Modifiers
<a class="headerlink leafygreen-ui-1kepx47" href="#modifiers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="modifiers">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
operator with the following modifiers:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Modifier
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/each/#mongodb-update-up.-each">
<code class="leafygreen-ui-1l06pbn">
$each
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Appends multiple values to the array field.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/slice/#mongodb-update-up.-slice">
<code class="leafygreen-ui-1l06pbn">
$slice
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Limits the number of array elements. Requires the use of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/each/#mongodb-update-up.-each">
<code class="leafygreen-ui-1l06pbn">
$each
</code>
</a>
modifier.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/sort/#mongodb-update-up.-sort">
<code class="leafygreen-ui-1l06pbn">
$sort
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Orders elements of the array. Requires the use of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/each/#mongodb-update-up.-each">
<code class="leafygreen-ui-1l06pbn">
$each
</code>
</a>
modifier.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/position/#mongodb-update-up.-position">
<code class="leafygreen-ui-1l06pbn">
$position
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Specifies the location in the array at which to insert the new
elements. Requires the use of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/each/#mongodb-update-up.-each">
<code class="leafygreen-ui-1l06pbn">
$each
</code>
</a>
modifier.
Without the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/position/#mongodb-update-up.-position">
<code class="leafygreen-ui-1l06pbn">
$position
</code>
</a>
modifier, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
appends the elements to the end of the array.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
When used with modifiers, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
operator has the form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $push: { <field1>: { <modifier1>: <value1>, ... }, ... } }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$push</span>: <!-- -->{ <<!-- -->field1<!-- -->><!-- -->: <!-- -->{ <<!-- -->modifier1<!-- -->><!-- -->: <<!-- -->value1<!-- -->><!-- -->,<!-- --> <!-- -->...<!-- --> }<!-- -->, <!-- -->...<!-- --> } }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The processing of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
operation with modifiers occur
in the following order, regardless of the order in which the modifiers
appear:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Update array to add elements in the correct position.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Apply sort, if specified.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Slice the array, if specified.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Store the array.
</p>
</li>
</ol>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Create the
<code class="leafygreen-ui-1l06pbn">
students
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.insertOne( { _id: 1, scores: [ 44, 78, 38, 80 ] } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">44</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span> ] } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Append a Value to an Array
<a class="headerlink leafygreen-ui-1kepx47" href="#append-a-value-to-an-array" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="append-a-value-to-an-array">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example appends
<code class="leafygreen-ui-1l06pbn">
89
</code>
to the
<code class="leafygreen-ui-1l06pbn">
scores
</code>
array:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.updateOne(\n { _id: 1 },\n { $push: { scores: 89 } }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$push</span>: <!-- -->{ <span class="lg-highlight-attr">scores</span>: <span class="lg-highlight-number">89</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Example output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 1, scores: [ 44, 78, 38, 80, 89 ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">44</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span>, <span class="lg-highlight-number">89</span> ] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-example-push-each">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Append a Value to Arrays in Multiple Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#append-a-value-to-arrays-in-multiple-documents" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="append-a-value-to-arrays-in-multiple-documents">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Add the following documents to the
<code class="leafygreen-ui-1l06pbn">
students
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.insertMany( [\n { _id: 2, scores: [ 45, 78, 38, 80, 89 ] } ,\n { _id: 3, scores: [ 46, 78, 38, 80, 89 ] } ,\n { _id: 4, scores: [ 47, 78, 38, 80, 89 ] }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">45</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span>, <span class="lg-highlight-number">89</span> ] } <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">46</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span>, <span class="lg-highlight-number">89</span> ] } <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">47</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span>, <span class="lg-highlight-number">89</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
operation appends
<code class="leafygreen-ui-1l06pbn">
95
</code>
to the
<code class="leafygreen-ui-1l06pbn">
scores
</code>
array in each document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.updateMany(\n { },\n { $push: { scores: 95 } }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">updateMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$push</span>: <!-- -->{ <span class="lg-highlight-attr">scores</span>: <span class="lg-highlight-number">95</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To confirm that each
<code class="leafygreen-ui-1l06pbn">
scores
</code>
array includes
<code class="leafygreen-ui-1l06pbn">
95
</code>
, run the following
operation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.find()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following results:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 1, scores: [ 44, 78, 38, 80, 89, 95 ] },\n { _id: 2, scores: [ 45, 78, 38, 80, 89, 95 ] },\n { _id: 3, scores: [ 46, 78, 38, 80, 89, 95 ] },\n { _id: 4, scores: [ 47, 78, 38, 80, 89, 95 ] }\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">44</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">95</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">45</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">95</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">46</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">95</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">scores</span>: <!-- -->[ <span class="lg-highlight-number">47</span>, <span class="lg-highlight-number">78</span>, <span class="lg-highlight-number">38</span>, <span class="lg-highlight-number">80</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">95</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Append Multiple Values to an Array
<a class="headerlink leafygreen-ui-1kepx47" href="#append-multiple-values-to-an-array" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="append-multiple-values-to-an-array">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/each/#mongodb-update-up.-each">
<code class="leafygreen-ui-1l06pbn">
$each
</code>
</a>
modifier to append
multiple values to the array field.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example appends each element of
<code class="leafygreen-ui-1l06pbn">
[ 90, 92, 85 ]
</code>
to
the
<code class="leafygreen-ui-1l06pbn">
scores
</code>
array for the document where the
<code class="leafygreen-ui-1l06pbn">
name
</code>
field
equals
<code class="leafygreen-ui-1l06pbn">
joe
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.updateOne(\n { name: \"joe\" },\n { $push: { scores: { $each: [ 90, 92, 85 ] } } }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"joe"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$push</span>: <!-- -->{ <span class="lg-highlight-attr">scores</span>: <!-- -->{ <span class="lg-highlight-attr">$each</span>: <!-- -->[ <span class="lg-highlight-number">90</span>, <span class="lg-highlight-number">92</span>, <span class="lg-highlight-number">85</span> ] } } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use
<code class="leafygreen-ui-1l06pbn">
$push
</code>
Operator with Multiple Modifiers
<a class="headerlink leafygreen-ui-1kepx47" href="#use--push-operator-with-multiple-modifiers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use--push-operator-with-multiple-modifiers">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Add the following document to the
<code class="leafygreen-ui-1l06pbn">
students
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.insertOne(\n {\n \"_id\" : 5,\n \"quizzes\" : [\n { \"wk\": 1, \"score\" : 10 },\n { \"wk\": 2, \"score\" : 8 },\n { \"wk\": 3, \"score\" : 5 },\n { \"wk\": 4, \"score\" : 6 }\n ]\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quizzes"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"wk"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"wk"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">8</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"wk"</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"wk"</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.-push" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</span>
</a>
operation uses:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/each/#mongodb-update-up.-each">
<code class="leafygreen-ui-1l06pbn">
$each
</code>
</a>
modifier to add multiple documents to the
<code class="leafygreen-ui-1l06pbn">
quizzes
</code>
array,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/sort/#mongodb-update-up.-sort">
<code class="leafygreen-ui-1l06pbn">
$sort
</code>
</a>
modifier to sort all the elements of the
modified
<code class="leafygreen-ui-1l06pbn">
quizzes
</code>
array by the
<code class="leafygreen-ui-1l06pbn">
score
</code>
field in descending
order, and
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/slice/#mongodb-update-up.-slice">
<code class="leafygreen-ui-1l06pbn">
$slice
</code>
</a>
modifier to keep only the
<strong>
first
</strong>
three
sorted elements of the
<code class="leafygreen-ui-1l06pbn">
quizzes
</code>
array.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.updateOne(\n { _id: 5 },\n {\n $push: {\n quizzes: {\n $each: [ { wk: 5, score: 8 }, { wk: 6, score: 7 }, { wk: 7, score: 6 } ],\n $sort: { score: -1 },\n $slice: 3\n }\n }\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$push</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quizzes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$each</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">wk</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">8</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">wk</span>: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">7</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">wk</span>: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">6</span> } ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">score</span>: <!-- -->-<span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$slice</span>: <span class="lg-highlight-number">3</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
After the operation only the three highest scoring quizzes are in the array:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 5,\n \"quizzes\" : [\n { \"wk\" : 1, \"score\" : 10 },\n { \"wk\" : 2, \"score\" : 8 },\n { \"wk\" : 5, \"score\" : 8 }\n ]\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quizzes"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"wk"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"wk"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">8</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"wk"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">8</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#mongodb-method-db.collection.updateMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateMany()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify">
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2dsphere/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
2dsphere Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#2dsphere-indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="2dsphere-indexes">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#use-cases" target="_self">
<span>
Use Cases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#get-started" target="_self">
<span>
Get Started
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#details" target="_self">
<span>
Details
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#sparse-property" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
sparse
</code>
Property
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#compound-2dsphere-indexes" target="_self">
<span>
Compound 2dsphere Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
2dsphere indexes support geospatial queries on an earth-like sphere. For
example, 2dsphere indexes can:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Determine points within a specified area.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Calculate proximity to a specified point.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Return exact matches on coordinate queries.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The values of the indexed field must be either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/geospatial-queries/#std-label-geospatial-geojson">
GeoJSON objects
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/geospatial-queries/#std-label-geospatial-legacy">
Legacy coordinate pairs
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For legacy coordinate pairs, the 2dsphere index converts the data to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geojson-point">
GeoJSON points
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To create a 2dsphere index, specify the string
<code class="leafygreen-ui-1l06pbn">
2dsphere
</code>
as the index
type:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.<collection>.createIndex( { <location> : \"2dsphere\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<!-- --><<!-- -->collection<!-- -->><!-- -->.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-tag lg-highlight-xml"><</span><span class="lg-highlight-name lg-highlight-tag lg-highlight-xml">location</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">field</span><span class="lg-highlight-tag lg-highlight-xml">></span><span class="lg-highlight-xml"> : "2dsphere" } )</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/create/#std-label-2dsphere-index-create">
creating a a 2dsphere index
</a>
, the first
value, or longitude, must be between -180 and 180, inclusive. The second value,
or latitude, must be between -90 and 90, inclusive. These coordinates "wrap"
around the sphere. For example, -179.9 and +179.9 are near neighbors.
</p>
</div>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Use Cases
<a class="headerlink leafygreen-ui-1kepx47" href="#use-cases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-cases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Use 2dsphere indexes to query and perform calculations on location data
where the data points appear on Earth, or another spherical surface. For
example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A food delivery application uses 2dsphere indexes to support
searches for nearby restaurants.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A route planning application uses 2dsphere indexes to calculate
the shortest distance between rest stops.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A city planner uses 2dsphere indexes to find parks that exist within
city limits.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Get Started
<a class="headerlink leafygreen-ui-1kepx47" href="#get-started" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="get-started">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To learn how to create and query 2dsphere indexes, see:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/create/#std-label-2dsphere-index-create">
Create a 2dsphere Index
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/query/geojson-bound-by-polygon/#std-label-2dsphere-query-geojson-objects-polygon">
Query for Locations Bound by a Polygon
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/query/proximity-to-geojson/#std-label-2dsphere-query-geojson-proximity">
Query for Locations Near a Point on a Sphere
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/query/intersections-of-geojson-objects/#std-label-2dsphere-query-intersection">
Query for Locations that Intersect a GeoJSON Object
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/query/points-within-circle-on-sphere/#std-label-2dsphere-query-points-within-circle-on-sphere">
Query for Locations within a Circle on a Sphere
</a>
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Details
<a class="headerlink leafygreen-ui-1kepx47" href="#details" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="details">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
2dsphere indexes are always
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-sparse/#std-label-index-type-sparse">
sparse
</a>
and have
special behaviors when created as part of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-index-type-compound">
compound index
<!-- -->
.
</a>
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
sparse
</code>
Property
<a class="headerlink leafygreen-ui-1kepx47" href="#sparse-property" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sparse-property">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
2dsphere indexes are always
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-sparse/#std-label-index-type-sparse">
sparse
</a>
. When
you create a 2dsphere index, MongoDB ignores the
<code class="leafygreen-ui-1l06pbn">
sparse
</code>
option.
</p>
<p class="leafygreen-ui-1kp3ins">
If an existing or newly inserted document does not contain a 2dsphere
index field (or the field is
<code class="leafygreen-ui-1l06pbn">
null
</code>
or an empty array), MongoDB does
not add an entry for the document to the index.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Compound 2dsphere Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#compound-2dsphere-indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compound-2dsphere-indexes">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For a compound index that includes a 2dsphere index key along with
keys of other types, only the 2dsphere index field determines
whether the index references a document.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A compound 2dsphere index can reference multiple location and
non-location fields. In contrast, a compound
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
2d
</a>
index can only reference one location field and one other field.
</p>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/geospatial-queries/#std-label-geospatial-queries">
Geospatial Queries
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query-geospatial/#std-label-geospatial-query-operators">
Geospatial Query Operators
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/geospatial-tutorial/#std-label-geospatial-tutorial-restaurants">
Find Restaurants with Geospatial Queries
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/restrictions/#std-label-geospatial-restrictions">
Geospatial Index Restrictions
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/wiredtiger/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
WiredTiger Storage Engine
<a class="headerlink leafygreen-ui-1kepx47" href="#wiredtiger-storage-engine" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="wiredtiger-storage-engine">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#operation-and-limitations" target="_self">
<span>
Operation and Limitations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#transaction--read-and-write--concurrency" target="_self">
<span>
Transaction (Read and Write) Concurrency
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#document-level-concurrency" target="_self">
<span>
Document Level Concurrency
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#snapshots-and-checkpoints" target="_self">
<span>
Snapshots and Checkpoints
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#journal" target="_self">
<span>
Journal
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compression" target="_self">
<span>
Compression
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#memory-use" target="_self">
<span>
Memory Use
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The WiredTiger storage engine is the default storage engine. For existing
deployments, if you do not specify the
<code class="leafygreen-ui-1l06pbn">
--storageEngine
</code>
or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.engine">
<code class="leafygreen-ui-1l06pbn">
storage.engine
</code>
</a>
setting, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance can
automatically determine the storage engine used to create the data files in the
<code class="leafygreen-ui-1l06pbn">
--dbpath
</code>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath">
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Deployments hosted in the following environments can use the WiredTiger
storage engine:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
All MongoDB Atlas deployments use the WiredTiger storage engine.
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To learn more about
<!-- -->
WiredTiger memory use
<!-- -->
for deployments hosted in MongoDB
Atlas, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/sizing-tier-selection/#memory" target="_self">
<span>
Memory
</span>
</a>
.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Operation and Limitations
<a class="headerlink leafygreen-ui-1kepx47" href="#operation-and-limitations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="operation-and-limitations">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following operational notes and limitations apply to the WiredTiger
engine:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can't pin documents to the WiredTiger cache.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
WiredTiger doesn't reserve a portion of the cache for reads and
another for writes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A heavy write workload can affect performance, but WiredTiger
prioritizes index caching in such cases.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
WiredTiger allocates its cache to the entire
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance.
WiredTiger doesn't allocate cache on a per-database or per-collection
level.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Transaction (Read and Write) Concurrency
<a class="headerlink leafygreen-ui-1kepx47" href="#transaction--read-and-write--concurrency" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="transaction--read-and-write--concurrency">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in version 7.0, MongoDB uses a default algorithm to dynamically
adjust the maximum number of concurrent storage engine transactions
(read and write tickets). The dynamic concurrent storage engine
transaction algorithm optimizes database throughput during cluster
overload. The maximum number of concurrent storage engine transactions
(read and write tickets) never exceeds 128 read tickets and 128
write tickets and may differ across nodes in a cluster. The maximum
number of read tickets and write tickets within a single node are always
equal.
</p>
<p class="leafygreen-ui-1kp3ins">
To specify a maximum number of read and write transactions (read and
write tickets) that the dynamic maximum can not exceed, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.storageEngineConcurrentReadTransactions">
<code class="leafygreen-ui-1l06pbn">
storageEngineConcurrentReadTransactions
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.storageEngineConcurrentWriteTransactions">
<code class="leafygreen-ui-1l06pbn">
storageEngineConcurrentWriteTransactions
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If you want to disable the dynamic concurrent storage engine
transactions algorithm, file a support request to work with a MongoDB
Technical Services Engineer.
</p>
<p class="leafygreen-ui-1kp3ins">
To view the number of concurrent read transactions (read tickets) and
write transactions (write tickets) allowed in the WiredTiger storage
engine, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-dbcommand-dbcmd.serverStatus">
<code class="leafygreen-ui-1l06pbn">
serverStatus
</code>
</a>
command and see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.queues.execution">
<code class="leafygreen-ui-1l06pbn">
queues.execution
</code>
</a>
response document.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
A low value of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.available">
<code class="leafygreen-ui-1l06pbn">
available
</code>
</a>
in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.queues.execution">
<code class="leafygreen-ui-1l06pbn">
queues.execution
</code>
</a>
does not indicate a cluster
overload. Use the number of queued read and write tickets as
an indication of cluster overload.
</p>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Document Level Concurrency
<a class="headerlink leafygreen-ui-1kepx47" href="#document-level-concurrency" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="document-level-concurrency">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
WiredTiger uses
<em>
document-level
</em>
concurrency control for write
operations. As a result, multiple clients can modify different
documents of a collection at the same time.
</p>
<p class="leafygreen-ui-1kp3ins">
For most read and write operations, WiredTiger uses optimistic
concurrency control. WiredTiger uses only intent locks at the global,
database and collection levels. When the storage engine detects
conflicts between two operations, one will incur a write conflict
causing MongoDB to transparently retry that operation.
</p>
<p class="leafygreen-ui-1kp3ins">
Some global operations, typically short lived operations involving
multiple databases, still require a global "instance-wide" lock.
Some other operations, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/renameCollection/#mongodb-dbcommand-dbcmd.renameCollection">
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
</a>
, still
require an exclusive database lock in certain circumstances.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-storage-wiredtiger-checkpoints">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Snapshots and Checkpoints
<a class="headerlink leafygreen-ui-1kepx47" href="#snapshots-and-checkpoints" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="snapshots-and-checkpoints">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
WiredTiger uses MultiVersion Concurrency Control (MVCC). At the start
of an operation, WiredTiger provides a point-in-time snapshot of the
data to the operation. A snapshot presents a consistent view of the
in-memory data.
</p>
<p class="leafygreen-ui-1kp3ins">
When writing to disk, WiredTiger writes all the data in a snapshot to
disk in a consistent way across all data files. The now-
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-durable">
durable
</a>
data act as a
<em>
checkpoint
</em>
in the data files. The
<em>
checkpoint
</em>
ensures
that the data files are consistent up to and including the last
checkpoint; i.e. checkpoints can act as recovery points.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB configures WiredTiger to create checkpoints, specifically, writing
the snapshot data to disk at intervals of 60 seconds.
</p>
<p class="leafygreen-ui-1kp3ins">
During the write of a new checkpoint, the previous checkpoint is still
valid. As such, even if MongoDB terminates or encounters an error while
writing a new checkpoint, upon restart, MongoDB can recover from the
last valid checkpoint.
</p>
<p class="leafygreen-ui-1kp3ins">
The new checkpoint becomes accessible and permanent when WiredTiger's
metadata table is atomically updated to reference the new checkpoint.
Once the new checkpoint is accessible, WiredTiger frees pages from the
old checkpoints.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-storage-snapshot-history">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Snapshot History Retention
<a class="headerlink leafygreen-ui-1kepx47" href="#snapshot-history-retention" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="snapshot-history-retention">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.minSnapshotHistoryWindowInSeconds">
<code class="leafygreen-ui-1l06pbn">
minSnapshotHistoryWindowInSeconds
</code>
</a>
parameter to specify how
long WiredTiger keeps the snapshot history.
</p>
<p class="leafygreen-ui-1kp3ins">
Increasing the value of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.minSnapshotHistoryWindowInSeconds">
<code class="leafygreen-ui-1l06pbn">
minSnapshotHistoryWindowInSeconds
</code>
</a>
increases disk usage because the server must maintain the history of
older modified values within the specified time window. The amount of
disk space used depends on your workload, with higher volume workloads
requiring more disk space.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB maintains the snapshot history in the
<code class="leafygreen-ui-1l06pbn">
WiredTigerHS.wt
</code>
file,
located in your specified
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath">
<code class="leafygreen-ui-1l06pbn">
dbPath
</code>
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-storage-wiredtiger-journal">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Journal
<a class="headerlink leafygreen-ui-1kepx47" href="#journal" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="journal">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
WiredTiger uses a write-ahead log (i.e. journal) in combination with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-storage-wiredtiger-checkpoints" target="_self">
<span>
checkpoints
</span>
</a>
to ensure data
durability.
</p>
<p class="leafygreen-ui-1kp3ins">
The WiredTiger journal persists all data modifications between
checkpoints. If MongoDB exits between checkpoints, it uses the journal
to replay all data modified since the last checkpoint. For information
on the frequency with which MongoDB writes the journal data to disk,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journal-process">
Journaling Process
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
WiredTiger journal is compressed using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-snappy">
snappy
</a>
compression
library. To specify a different compression algorithm or no
compression, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.wiredTiger.engineConfig.journalCompressor">
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.journalCompressor
</code>
</a>
setting.
For details on changing the journal compressor, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-journaling/#std-label-manage-journaling-change-wt-journal-compressor">
Change WiredTiger Journal Compressor
<!-- -->
.
</a>
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If a log record less than or equal to 128 bytes (the mininum
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-wt-jouraling-record">
log record size for WiredTiger
</a>
),
WiredTiger does not compress that record.
</p>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journaling-wiredTiger">
Journaling with WiredTiger
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-storage-wiredtiger-compression">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compression
<a class="headerlink leafygreen-ui-1kepx47" href="#compression" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compression">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
With WiredTiger, MongoDB supports compression for all collections and
indexes. Compression minimizes storage use at the expense of additional
CPU.
</p>
<p class="leafygreen-ui-1kp3ins">
By default, WiredTiger uses block compression with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-snappy">
snappy
</a>
compression library for all collections and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-prefix-compression">
prefix compression
</a>
for all indexes.
</p>
<p class="leafygreen-ui-1kp3ins">
For collections, the following block compression libraries are also available:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zlib">
zlib
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zstd">
zstd
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To specify an alternate compression algorithm or no compression, use
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.wiredTiger.collectionConfig.blockCompressor">
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.collectionConfig.blockCompressor
</code>
</a>
setting.
</p>
<p class="leafygreen-ui-1kp3ins">
For indexes, to disable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-prefix-compression">
prefix compression
</a>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.wiredTiger.indexConfig.prefixCompression">
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.indexConfig.prefixCompression
</code>
</a>
setting.
</p>
<p class="leafygreen-ui-1kp3ins">
Compression settings are also configurable on a per-collection and
per-index basis during collection and index creation. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createCollection/#std-label-create-collection-storage-engine-options">
Specify Storage Engine Options
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#std-label-createIndex-options">
db.collection.createIndex() storageEngine option
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For most workloads, the default compression settings balance storage
efficiency and processing requirements.
</p>
<p class="leafygreen-ui-1kp3ins">
The WiredTiger journal is also compressed by default. For information
on journal compression, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-storage-wiredtiger-journal" target="_self">
<span>
Journal
<!-- -->
.
</span>
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-wiredtiger-RAM">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Memory Use
<a class="headerlink leafygreen-ui-1kepx47" href="#memory-use" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="memory-use">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
With WiredTiger, MongoDB utilizes both the WiredTiger internal cache
and the filesystem cache.
</p>
<p class="leafygreen-ui-1kp3ins">
The default WiredTiger internal cache size is the larger of either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
50% of (RAM - 1 GB), or
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
256 MB.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For example, on a system with a total of 4GB of RAM the
WiredTiger cache uses 1.5GB of RAM (
<code class="leafygreen-ui-1l06pbn">
0.5 * (4 GB - 1 GB) =
1.5 GB
</code>
). Conversely, on a system with a total of 1.25 GB of
RAM WiredTiger allocates 256 MB to the WiredTiger cache
because that is more than half of the total RAM minus one
gigabyte (
<code class="leafygreen-ui-1l06pbn">
0.5 * (1.25 GB - 1 GB) = 128 MB < 256 MB
</code>
).
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
In some instances, such as when running in a container, the database
can have memory constraints that are lower than the total system
memory. In such instances, this memory limit, rather than the total
system memory, is used as the maximum RAM available.
</p>
<p class="leafygreen-ui-1kp3ins">
To see the memory limit, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/hostInfo/#mongodb-data-hostInfo.system.memLimitMB">
<code class="leafygreen-ui-1l06pbn">
hostInfo.system.memLimitMB
</code>
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
By default, WiredTiger uses Snappy block compression for all collections
and prefix compression for all indexes. Compression defaults are configurable
at a global level and can also be set on a per-collection and per-index
basis during collection and index creation.
</p>
<p class="leafygreen-ui-1kp3ins">
Different representations are used for data in the WiredTiger internal cache
versus the on-disk format:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Data in the filesystem cache is the same as the on-disk format, including
benefits of any compression for data files. The filesystem cache is used
by the operating system to reduce disk I/O.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Indexes loaded in the WiredTiger internal cache have a different data
representation to the on-disk format, but can still take advantage of
index prefix compression to reduce RAM usage. Index prefix compression
deduplicates common prefixes from indexed fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Collection data in the WiredTiger internal cache is uncompressed
and uses a different representation from the on-disk format. Block
compression can provide significant on-disk storage savings, but
data must be uncompressed to be manipulated by the server.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
With the filesystem cache, MongoDB automatically uses all free memory
that is not used by the WiredTiger cache or by other processes.
</p>
<p class="leafygreen-ui-1kp3ins">
To adjust the size of the WiredTiger internal cache, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.wiredTiger.engineConfig.cacheSizeGB">
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.cacheSizeGB
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--wiredTigerCacheSizeGB">
<code class="leafygreen-ui-1l06pbn">
--wiredTigerCacheSizeGB
</code>
</a>
. Avoid increasing the WiredTiger
internal cache size above its default value.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/cursor.noCursorTimeout/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
cursor.noCursorTimeout()
<a class="headerlink leafygreen-ui-1kepx47" href="#cursor.nocursortimeout--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="cursor.nocursortimeout--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
cursor.noCursorTimeout()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.noCursorTimeout" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-cursor.noCursorTimeout">
</div>
</a>
</dt>
<dd>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for a language-specific driver, such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Instructs the server to avoid closing a cursor automatically after a period
of inactivity.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.noCursorTimeout" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
noCursorTimeout()
</code>
</span>
</a>
method has the following
prototype form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find(<query>).noCursorTimeout()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<<!-- -->query<!-- -->><!-- -->).<span class="lg-highlight-title lg-highlight-function">noCursorTimeout</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Session Idle Timeout Overrides
<code class="leafygreen-ui-1l06pbn">
noCursorTimeout
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#session-idle-timeout-overrides-nocursortimeout" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="session-idle-timeout-overrides-nocursortimeout">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB drivers and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
associate all operations with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/server-sessions/">
server session
</a>
, with the exception of unacknowledged
write operations. For operations not explicitly associated with a
session (i.e. using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo.startSession/#mongodb-method-Mongo.startSession">
<code class="leafygreen-ui-1l06pbn">
Mongo.startSession()
</code>
</a>
), MongoDB drivers
and
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
create an implicit session and associate it
with the operation.
</p>
<p class="leafygreen-ui-1kp3ins">
If a session is idle for longer than 30 minutes, the MongoDB server
marks that session as expired and may close it at any time. When the
MongoDB server closes the session, it also kills any in-progress
operations and open cursors associated with the session. This
includes cursors configured with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.noCursorTimeout" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
noCursorTimeout()
</code>
</span>
</a>
or
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.maxTimeMS/#mongodb-method-cursor.maxTimeMS">
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</a>
greater than 30 minutes.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider an application that issues a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
db.collection.find()
</code>
</a>
with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.noCursorTimeout" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
cursor.noCursorTimeout()
</code>
</span>
</a>
. The server returns a cursor along
with a batch of documents defined by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.batchSize/#mongodb-method-cursor.batchSize">
<code class="leafygreen-ui-1l06pbn">
cursor.batchSize()
</code>
</a>
of
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
find()
</code>
</a>
. The session refreshes each time the
application requests a new batch of documents from the server. However,
if the application takes longer than 30 minutes to process the current
batch of documents, the session is marked as expired and closed. When
the server closes the session, it also kills the cursor
<em>
despite
</em>
the
cursor being configured with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.noCursorTimeout" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
noCursorTimeout()
</code>
</span>
</a>
. When the
application requests the next batch of documents, the server returns an
error.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-refresh-session-cursor-example">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Refresh a Cursor with
<code class="leafygreen-ui-1l06pbn">
refreshSessions
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#refresh-a-cursor-with-refreshsessions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="refresh-a-cursor-with-refreshsessions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For operations that return a cursor, if the cursor may be idle for
longer than 30 minutes, issue the operation within an explicit session
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo.startSession/#mongodb-method-Mongo.startSession">
<code class="leafygreen-ui-1l06pbn">
Mongo.startSession()
</code>
</a>
and periodically refresh the
session using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/refreshSessions/#mongodb-dbcommand-dbcmd.refreshSessions">
<code class="leafygreen-ui-1l06pbn">
refreshSessions
</code>
</a>
command. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var session = db.getMongo().startSession()\nvar sessionId = session\nsessionId // show the sessionId\n\nvar cursor = session.getDatabase(\"examples\").getCollection(\"data\").find().noCursorTimeout()\nvar refreshTimestamp = new Date() // take note of time at operation start\n\nwhile (cursor.hasNext()) {\n\n // Check if more than 5 minutes have passed since the last refresh\n if ( (new Date()-refreshTimestamp)/1000 > 300 ) {\n print(\"refreshing session\")\n db.adminCommand({\"refreshSessions\" : [sessionId]})\n refreshTimestamp = new Date()\n }\n\n // process cursor normally\n\n}","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">var session = db.getMongo().startSession()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">var sessionId = session</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sessionId // show the sessionId</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">var cursor = session.getDatabase(<span class="lg-highlight-string">"examples"</span>).getCollection(<span class="lg-highlight-string">"data"</span>).find().noCursorTimeout()</td></tr><tr class=""><td class="leafygreen-ui-7razhx">var refreshTimestamp = new Date() // take note of time at operation start</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">while</span> (cursor.hasNext()) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> // Check <span class="lg-highlight-keyword">if</span> more than 5 minutes have passed since the last refresh</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> ( (new Date()-refreshTimestamp)/1000 > 300 ) {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-built_in">print</span>(<span class="lg-highlight-string">"refreshing session"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> db.adminCommand({<span class="lg-highlight-string">"refreshSessions"</span> : [sessionId]})</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> refreshTimestamp = new Date()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> // process cursor normally</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In the example operation, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
db.collection.find()
</code>
</a>
method is
associated with an explicit session. The cursor is configured with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.noCursorTimeout" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
cursor.noCursorTimeout()
</code>
</span>
</a>
to prevent the server from closing
the cursor if idle. The
<code class="leafygreen-ui-1l06pbn">
while
</code>
loop includes a block that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/refreshSessions/#mongodb-dbcommand-dbcmd.refreshSessions">
<code class="leafygreen-ui-1l06pbn">
refreshSessions
</code>
</a>
to refresh the session every 5 minutes.
Since the session will never exceed the 30 minute idle timeout, the
cursor can remain open indefinitely.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB drivers, defer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver documentation
</span>
</a>
for instructions and syntax for creating sessions.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/timeseries/timeseries-automatic-removal/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Set up Automatic Removal for Time Series Collections (TTL)
<a class="headerlink leafygreen-ui-1kepx47" href="#set-up-automatic-removal-for-time-series-collections--ttl-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="set-up-automatic-removal-for-time-series-collections--ttl-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#enable-automatic-removal-on-a-collection" target="_self">
<span>
Enable Automatic Removal on a Collection
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#change-the-expireafterseconds-parameter" target="_self">
<span>
Change the
<code class="css-1kekw28 e1wawog0">
expireAfterSeconds
</code>
Parameter
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#retrieve-the-current-value-of-expireafterseconds" target="_self">
<span>
Retrieve the Current Value of
<code class="css-1kekw28 e1wawog0">
expireAfterSeconds
</code>
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#disable-automatic-removal" target="_self">
<span>
Disable Automatic Removal
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#timing-of-delete-operations" target="_self">
<span>
Timing of Delete Operations
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
When you create a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
time series collection
</a>
, you can set up automatic removal of
documents older than a specified number of seconds by using the
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
parameter:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.createCollection(\n \"weather24h\",\n {\n timeseries: {\n timeField: \"timestamp\",\n metaField: \"metadata\",\n granularity: \"hours\"\n },\n expireAfterSeconds: 86400\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">createCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"weather24h"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeseries</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeField</span>: <span class="lg-highlight-string">"timestamp"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaField</span>: <span class="lg-highlight-string">"metadata"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">granularity</span>: <span class="lg-highlight-string">"hours"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">expireAfterSeconds</span>: <span class="lg-highlight-number">86400</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The expiration threshold is the
<code class="leafygreen-ui-1l06pbn">
timeField
</code>
field value plus the
specified number of seconds. Consider the following document in the
<code class="leafygreen-ui-1l06pbn">
weather24h
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"metadata\": {\"sensorId\": 5578, \"type\": \"temperature\"},\n \"timestamp\": ISODate(\"2021-05-18T10:00:00.000Z\"),\n \"temp\": 12\n}"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "metadata": {"sensorId": 5578, "type": "temperature"},</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "timestamp": ISODate("2021-05-18T10:00:00.000Z"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "temp": 12</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The document would expire from the database at
<code class="leafygreen-ui-1l06pbn">
"2021-05-19T10:00:00.000Z"
</code>
. Once all documents in a bucket are
expired, the background task that removes expired buckets removes the
bucket during the next run. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-timeseries-collection-delete-operations-timing" target="_self">
<span>
Timing of Delete Operations
</span>
</a>
for more
information.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Enable Automatic Removal on a Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-automatic-removal-on-a-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enable-automatic-removal-on-a-collection">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To enable automatic removal of documents for an existing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
time
series collection
</a>
, issue the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collMod/#mongodb-dbcommand-dbcmd.collMod">
<code class="leafygreen-ui-1l06pbn">
collMod
</code>
</a>
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand({\n collMod: \"weather24h\",\n expireAfterSeconds: 604801\n})","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">collMod</span>: <span class="lg-highlight-string">"weather24h"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">expireAfterSeconds</span>: <span class="lg-highlight-number">604801</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">})</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Change the
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#change-the-expireafterseconds-parameter" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="change-the-expireafterseconds-parameter">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To change the
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
parameter value, issue the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collMod/#mongodb-dbcommand-dbcmd.collMod">
<code class="leafygreen-ui-1l06pbn">
collMod
</code>
</a>
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand({\n collMod: \"weather24h\",\n expireAfterSeconds: 604801\n})","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">collMod</span>: <span class="lg-highlight-string">"weather24h"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">expireAfterSeconds</span>: <span class="lg-highlight-number">604801</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">})</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Retrieve the Current Value of
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-the-current-value-of-expireafterseconds" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-the-current-value-of-expireafterseconds">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To retrieve the current value of
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/listCollections/#mongodb-dbcommand-dbcmd.listCollections">
<code class="leafygreen-ui-1l06pbn">
listCollections
</code>
</a>
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand( { listCollections: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>( <!-- -->{ <span class="lg-highlight-attr">listCollections</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The result document contains a document for the time series collection
which contains the
<code class="leafygreen-ui-1l06pbn">
options.expireAfterSeconds
</code>
field.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n cursor: {\n id: <number>,\n ns: 'test.$cmd.listCollections',\n firstBatch: [\n {\n name: <string>,\n type: 'timeseries',\n options: {\n expireAfterSeconds: <number>,\n timeseries: { ... }\n },\n ...\n },\n ...\n ]\n }\n }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cursor</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">id</span>: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ns</span>: <span class="lg-highlight-string">'test.$cmd.listCollections'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstBatch</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'timeseries'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">options</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">expireAfterSeconds</span>: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeseries</span>: <!-- -->{ <!-- -->...<!-- --> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Disable Automatic Removal
<a class="headerlink leafygreen-ui-1kepx47" href="#disable-automatic-removal" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="disable-automatic-removal">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To disable automatic removal, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collMod/#mongodb-dbcommand-dbcmd.collMod">
<code class="leafygreen-ui-1l06pbn">
collMod
</code>
</a>
command to
set
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
to
<code class="leafygreen-ui-1l06pbn">
off
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand({\n collMod: \"weather24h\",\n expireAfterSeconds: \"off\"\n})","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">collMod</span>: <span class="lg-highlight-string">"weather24h"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">expireAfterSeconds</span>: <span class="lg-highlight-string">"off"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">})</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-timeseries-collection-delete-operations-timing">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Timing of Delete Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#timing-of-delete-operations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="timing-of-delete-operations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB doesn't guarantee that expired data will be deleted immediately
upon expiration. Once all documents in a bucket are expired, the
background task that removes expired buckets removes the bucket during
the next run. The maximum span of time that a single bucket is allowed
to cover is controlled by the
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
of the time series
collection:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:40%"/>
<col style="width:60%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Covered Time Span
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"seconds"
</code>
(default)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
one hour
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"minutes"
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
24 hours
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"hours"
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
30 days
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The background task that removes expired buckets runs every 60 seconds.
Therefore, documents may remain in a collection during the period
between the expiration of the document, the expiration of all other
documents in the bucket and the running of the background task.
</p>
<p class="leafygreen-ui-1kp3ins">
Because the duration of the removal operation depends on the workload of
your mongod instance, expired data may exist for some time beyond the 60
second period between runs of the background task.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/administration/self-managed-administration/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Self-Managed Administration
<a class="headerlink leafygreen-ui-1kepx47" href="#self-managed-administration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="self-managed-administration">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
Learn how to operate and maintain self-managed MongoDB deployments.
Familiarize yourself with best practices for running self-managed
deployments in production.
</p>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-production-notes">
Production Notes
</a>
</dt>
<dd class="css-1ufxuu7">
Learn about system configurations that affect MongoDB, especially
when running in production.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-checklist-operations/#std-label-operations-checklist">
Operations Checklist
</a>
</dt>
<dd class="css-1ufxuu7">
Learn how to avoid issues in your production MongoDB deployment.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/self-managed-performance/#std-label-self-managed-performance">
Performance
</a>
</dt>
<dd class="css-1ufxuu7">
Learn how to monitor and improve performance for self-managed
deployments.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/self-managed-configuration-and-maintenance/#std-label-self-managed-configuration-and-maintenance">
Configuration and Maintenance
</a>
</dt>
<dd class="css-1ufxuu7">
Learn how to configure and administer self-managed deployments.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/backups/#std-label-backup-methods">
Backup Methods
</a>
</dt>
<dd class="css-1ufxuu7">
Learn how to backup data on self-managed deployments.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/monitoring/#std-label-monitoring-for-mdb">
Monitoring
</a>
</dt>
<dd class="css-1ufxuu7">
Learn how to assess your self-managed deployment and monitor key
metrics.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/exit-codes/#std-label-server-exit-codes">
Exit Codes
</a>
</dt>
<dd class="css-1ufxuu7">
Learn the different MongoDB exit codes and how they are caused.
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/core/sharded-cluster-components/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Sharded Cluster Components
<a class="headerlink leafygreen-ui-1kepx47" href="#sharded-cluster-components" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sharded-cluster-components">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#production-configuration" target="_self">
<span>
Production Configuration
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#development-configuration" target="_self">
<span>
Development Configuration
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
A MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster
</a>
consists of the following components:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-shards/#std-label-shards-concepts">
shard
</a>
: Each shard contains a
subset of the sharded data. Each shard must be deployed as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/">
mongos
</a>
: The
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
acts as a
query router, providing an interface between client applications and the
sharded cluster.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server">
config servers
</a>
: Config
servers store metadata and configuration settings for the cluster. Config
servers must be deployed as a replica set (CSRS).
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sc-production-configuration">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Production Configuration
<a class="headerlink leafygreen-ui-1kepx47" href="#production-configuration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="production-configuration">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In a production cluster, ensure that data is redundant and
that your systems are highly available. Consider the following
for a production sharded cluster deployment:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Deploy Config Servers as a 3 member
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Deploy each Shard as a 3 member
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Deploy one or more
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
routers
</p>
</li>
</ul>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replica Set Distribution
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-distribution" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replica-set-distribution">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Where possible, consider deploying one member of each replica set
in a site suitable for being a disaster recovery location.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Distributing replica set members across two data centers provides
benefit over a single data center. In a two data center
distribution,
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If one of the data centers goes down, the data is still available
for reads unlike a single data center distribution.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the data center with a minority of the members goes down, the
replica set can still serve write operations as well as read
operations.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
However, if the data center with the majority of the members goes
down, the replica set becomes read-only.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If possible, distribute members across at least three data centers.
For config server replica sets (CSRS), the best practice is to
distribute across three (or more depending on the number of members)
centers. If the cost of the third data center is prohibitive, one
distribution possibility is to evenly distribute the data bearing
members across the two data centers and store the remaining member
in the cloud if your company policy allows.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Number of Shards
<a class="headerlink leafygreen-ui-1kepx47" href="#number-of-shards" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="number-of-shards">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Sharding requires at least two shards to distribute sharded data. Single
shard sharded clusters may be useful if you plan on enabling sharding in
the near future, but do not need to at the time of deployment.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharded-cluster-components-distribution">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Number of
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
and Distribution
<a class="headerlink leafygreen-ui-1kepx47" href="#number-of-mongos-and-distribution" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="number-of-mongos-and-distribution">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
routers support high availability and scalability
when deploying multiple
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
instances. If a proxy or load
balancer is between the application and the
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
routers, you
must configure it for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-client-affinity">
client affinity
</a>
. Client affinity allows
every connection from a single client to reach the same
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
For shard-level high availability, either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Add
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
instances on the same hardware where
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
instances are already running.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Embed
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
routers at the application level.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
routers communicate frequently with your config
servers. As you increase the number of routers, performance may degrade.
If performance degrades, reduce the number of routers. Your deployment
should not have more than 30
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
routers.
</p>
<p class="leafygreen-ui-1kp3ins">
The following diagram shows a common sharded cluster architecture used
in production:
</p>
<div class="gatsby-image-wrapper gatsby-image-wrapper-constrained leafygreen-ui-12xaq6r" data-gatsby-image-wrapper="">
<div style="max-width:960px;display:block">
<img alt="" aria-hidden="true" role="presentation" src="data:image/svg+xml;charset=utf-8,%3Csvg%20height='540'%20width='960'%20xmlns='http://www.w3.org/2000/svg'%20version='1.1'%3E%3C/svg%3E" style="max-width:100%;display:block;position:static"/>
</div>
<div aria-hidden="true" data-placeholder-image="" style="opacity:1;transition:opacity 500ms linear">
</div>
<img alt="Diagram that shows a production-level sharded cluster
containing multiple shards and mongos routers." data-main-image="" decoding="async" height="540" loading="lazy" sizes="(min-width: 960px) 960px, 100vw" src="/docs/manual/static/1112d075b61fb59a49076c865c6e8f60/bde8a/sharded-cluster-production-architecture.webp" srcset="/docs/manual/static/1112d075b61fb59a49076c865c6e8f60/769c8/sharded-cluster-production-architecture.webp 240w,/docs/manual/static/1112d075b61fb59a49076c865c6e8f60/3a3a2/sharded-cluster-production-architecture.webp 480w,/docs/manual/static/1112d075b61fb59a49076c865c6e8f60/bde8a/sharded-cluster-production-architecture.webp 960w" style="--border-color:#C1C7C6;opacity:0" width="960"/>
<noscript>
<img alt="Diagram that shows a production-level sharded cluster
containing multiple shards and mongos routers." data-gatsby-image-ssr="" data-main-image="" decoding="async" height="540" loading="lazy" sizes="(min-width: 960px) 960px, 100vw" src="/docs/manual/static/1112d075b61fb59a49076c865c6e8f60/bde8a/sharded-cluster-production-architecture.webp" srcset="/docs/manual/static/1112d075b61fb59a49076c865c6e8f60/769c8/sharded-cluster-production-architecture.webp 240w,/docs/manual/static/1112d075b61fb59a49076c865c6e8f60/3a3a2/sharded-cluster-production-architecture.webp 480w,/docs/manual/static/1112d075b61fb59a49076c865c6e8f60/bde8a/sharded-cluster-production-architecture.webp 960w" style="--border-color:#C1C7C6;opacity:0" width="960"/>
</noscript>
<script type="module">
const t="undefined"!=typeof HTMLImageElement&&"loading"in HTMLImageElement.prototype;if(t){const t=document.querySelectorAll("img[data-main-image]");for(let e of t){e.dataset.src&&(e.setAttribute("src",e.dataset.src),e.removeAttribute("data-src")),e.dataset.srcset&&(e.setAttribute("srcset",e.dataset.srcset),e.removeAttribute("data-srcset"));const t=e.parentNode.querySelectorAll("source[data-srcset]");for(let e of t)e.setAttribute("srcset",e.dataset.srcset),e.removeAttribute("data-srcset");e.complete&&(e.style.opacity=1,e.parentNode.parentNode.querySelector("[data-placeholder-image]").style.opacity=0)}}
</script>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Development Configuration
<a class="headerlink leafygreen-ui-1kepx47" href="#development-configuration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="development-configuration">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For testing and development, you can deploy a sharded cluster with a
minimum number of components. These
<strong>
non-production
</strong>
clusters have the
following components:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
One
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A single shard
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server">
config server
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The following diagram shows a sharded cluster architecture used for
<strong>
development only
</strong>
:
</p>
<div class="gatsby-image-wrapper gatsby-image-wrapper-constrained leafygreen-ui-12xaq6r" data-gatsby-image-wrapper="">
<div style="max-width:960px;display:block">
<img alt="" aria-hidden="true" role="presentation" src="data:image/svg+xml;charset=utf-8,%3Csvg%20height='540'%20width='960'%20xmlns='http://www.w3.org/2000/svg'%20version='1.1'%3E%3C/svg%3E" style="max-width:100%;display:block;position:static"/>
</div>
<div aria-hidden="true" data-placeholder-image="" style="opacity:1;transition:opacity 500ms linear">
</div>
<img alt="Diagram that shows a development sharded cluster
containing a single shard and mongos router." data-main-image="" decoding="async" height="540" loading="lazy" sizes="(min-width: 960px) 960px, 100vw" src="/docs/manual/static/4bc31b65412fd833c8d44cd4642b95f4/bde8a/sharded-cluster-test-architecture.webp" srcset="/docs/manual/static/4bc31b65412fd833c8d44cd4642b95f4/769c8/sharded-cluster-test-architecture.webp 240w,/docs/manual/static/4bc31b65412fd833c8d44cd4642b95f4/3a3a2/sharded-cluster-test-architecture.webp 480w,/docs/manual/static/4bc31b65412fd833c8d44cd4642b95f4/bde8a/sharded-cluster-test-architecture.webp 960w" style="--border-color:#C1C7C6;opacity:0" width="960"/>
<noscript>
<img alt="Diagram that shows a development sharded cluster
containing a single shard and mongos router." data-gatsby-image-ssr="" data-main-image="" decoding="async" height="540" loading="lazy" sizes="(min-width: 960px) 960px, 100vw" src="/docs/manual/static/4bc31b65412fd833c8d44cd4642b95f4/bde8a/sharded-cluster-test-architecture.webp" srcset="/docs/manual/static/4bc31b65412fd833c8d44cd4642b95f4/769c8/sharded-cluster-test-architecture.webp 240w,/docs/manual/static/4bc31b65412fd833c8d44cd4642b95f4/3a3a2/sharded-cluster-test-architecture.webp 480w,/docs/manual/static/4bc31b65412fd833c8d44cd4642b95f4/bde8a/sharded-cluster-test-architecture.webp 960w" style="--border-color:#C1C7C6;opacity:0" width="960"/>
</noscript>
<script type="module">
const t="undefined"!=typeof HTMLImageElement&&"loading"in HTMLImageElement.prototype;if(t){const t=document.querySelectorAll("img[data-main-image]");for(let e of t){e.dataset.src&&(e.setAttribute("src",e.dataset.src),e.removeAttribute("data-src")),e.dataset.srcset&&(e.setAttribute("srcset",e.dataset.srcset),e.removeAttribute("data-srcset"));const t=e.parentNode.querySelectorAll("source[data-srcset]");for(let e of t)e.setAttribute("srcset",e.dataset.srcset),e.removeAttribute("data-srcset");e.complete&&(e.style.opacity=1,e.parentNode.parentNode.querySelector("[data-placeholder-image]").style.opacity=0)}}
</script>
</div>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Use the test cluster architecture for testing and
development only.
</p>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/deploy-shard-cluster/">
Deploy a Self-Managed Sharded Cluster
</a>
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$rand (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-rand--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-rand--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-rand" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-rand">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns a random float between 0 and 1 each time it is called.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-rand" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $rand: {} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$rand</span>: <!-- -->{<!-- -->} }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-rand" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
</span>
</a>
operator doesn't take any arguments.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Each time
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
is called it will return a floating point value
that has up to 17 digits after the decimal point. Trailing 0s are
dropped so the actual number of digits may vary.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Generate Random Data Points
<a class="headerlink leafygreen-ui-1kepx47" href="#generate-random-data-points" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="generate-random-data-points">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
This example models charitable donations. The collection starts with a
list of donors.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.donors.insertMany(\n [\n { donorId: 1000, amount: 0, frequency: 1 },\n { donorId: 1001, amount: 0, frequency: 2 },\n { donorId: 1002, amount: 0, frequency: 1 },\n { donorId: 1003, amount: 0, frequency: 2 },\n { donorId: 1004, amount: 0, frequency: 1 }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">donors</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1000</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1001</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1002</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1003</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1004</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">frequency</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
We use an aggregation pipeline to update each document with a random
donation amount.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.donors.aggregate(\n [\n { $set: { amount: { $multiply: [ { $rand: {} }, 100 ] } } },\n { $set: { amount: { $floor: \"$amount\" } } },\n { $merge: \"donors\" }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">donors</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">amount</span>: <!-- -->{ <span class="lg-highlight-attr">$multiply</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$rand</span>: <!-- -->{<!-- -->} }<!-- -->, <span class="lg-highlight-number">100</span> ] } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">amount</span>: <!-- -->{ <span class="lg-highlight-attr">$floor</span>: <span class="lg-highlight-string">"$amount"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$merge</span>: <span class="lg-highlight-string">"donors"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The first
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
</a>
stage updates the
<code class="leafygreen-ui-1l06pbn">
amount
</code>
field. An
initial value between 0 and 1 is generated using
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
. Then
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/multiply/#mongodb-expression-exp.-multiply">
<code class="leafygreen-ui-1l06pbn">
$multiply
</code>
</a>
scales it upward 100 times.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/floor/#mongodb-expression-exp.-floor">
<code class="leafygreen-ui-1l06pbn">
$floor
</code>
</a>
operator in the second
<code class="leafygreen-ui-1l06pbn">
$set
</code>
stage removes
the decimal portion from the
<code class="leafygreen-ui-1l06pbn">
amount
</code>
to leave an integer value.
</p>
<p class="leafygreen-ui-1kp3ins">
Finally,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
writes the random value created in the
previous steps to the
<code class="leafygreen-ui-1l06pbn">
amount
</code>
field, updating it for each document
in the
<code class="leafygreen-ui-1l06pbn">
donors
</code>
collection.
</p>
<p class="leafygreen-ui-1kp3ins">
You can view the results with a projection stage:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.donors.aggregate(\n [\n { $project: {_id: 0, donorId: 1, amount: 1 } }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">donors</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{<span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">donorId</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">1</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The projection shows the scaled amounts are now random values in the
range from 0 to 99.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"donorId\" : 1000, \"amount\" : 27 }\n{ \"donorId\" : 1001, \"amount\" : 10 }\n{ \"donorId\" : 1002, \"amount\" : 88 }\n{ \"donorId\" : 1003, \"amount\" : 73 }\n{ \"donorId\" : 1004, \"amount\" : 5 }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1000</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">27</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1001</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">10</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1002</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">88</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1003</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">73</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"donorId"</span> <!-- -->: <span class="lg-highlight-number">1004</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">5</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Select Random Items From a Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#select-random-items-from-a-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="select-random-items-from-a-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can use
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
in an aggregation pipeline to select random
documents from a collection. Consider a collection of voter records:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.voters.insertMany(\n [\n { name: \"Archibald\", voterId: 4321, district: 3, registered: true },\n { name: \"Beckham\", voterId: 4331, district: 3, registered: true },\n { name: \"Carolin\", voterId: 5321, district: 4, registered: true },\n { name: \"Debarge\", voterId: 4343, district: 3, registered: false },\n { name: \"Eckhard\", voterId: 4161, district: 3, registered: false },\n { name: \"Faberge\", voterId: 4300, district: 1, registered: true },\n { name: \"Grimwald\", voterId: 4111, district: 3, registered: true },\n { name: \"Humphrey\", voterId: 2021, district: 3, registered: true },\n { name: \"Idelfon\", voterId: 1021, district: 4, registered: true },\n { name: \"Justo\", voterId: 9891, district: 3, registered: false }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">voters</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Archibald"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4321</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Beckham"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4331</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Carolin"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">5321</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Debarge"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4343</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">false</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Eckhard"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4161</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">false</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Faberge"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4300</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Grimwald"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">4111</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Humphrey"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">2021</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Idelfon"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">1021</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Justo"</span>, <span class="lg-highlight-attr">voterId</span>: <span class="lg-highlight-number">9891</span>, <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Imagine you want to select about half of the voters in District 3 to do
some polling.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.voters.aggregate(\n [\n { $match: { district: 3 } },\n { $match: { $expr: { $lt: [0.5, {$rand: {} } ] } } },\n { $project: { _id: 0, name: 1, registered: 1 } }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">voters</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">district</span>: <span class="lg-highlight-number">3</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$lt</span>: <!-- -->[<span class="lg-highlight-number">0.5</span>, <!-- -->{<span class="lg-highlight-attr">$rand</span>: <!-- -->{<!-- -->} } ] } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">registered</span>: <span class="lg-highlight-number">1</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The first pipeline stage matches all documents where the voter is from
district 3.
</p>
<p class="leafygreen-ui-1kp3ins">
The second
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match">
<code class="leafygreen-ui-1l06pbn">
$match
</code>
</a>
stage uses
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
in a match
expression to further refine the selection. For each document,
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
generates a value between 0 and 1. The threshold of
<code class="leafygreen-ui-1l06pbn">
0.5
</code>
in the less than
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lt/#mongodb-expression-exp.-lt">
<code class="leafygreen-ui-1l06pbn">
($lt)
</code>
</a>
comparison means that
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</code>
</a>
will be true for about half the documents.
</p>
<p class="leafygreen-ui-1kp3ins">
In the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
<code class="leafygreen-ui-1l06pbn">
$project
</code>
</a>
stage the selected documents are filtered
to return the
<code class="leafygreen-ui-1l06pbn">
name
</code>
and
<code class="leafygreen-ui-1l06pbn">
registered
</code>
fields. There are 7 voters in
District 3, running the code selects about half of them.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"name\" : \"Archibald\", \"registered\" : true }\n{ \"name\" : \"Debarge\", \"registered\" : false }\n{ \"name\" : \"Humphrey\", \"registered\" : true }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Archibald"</span>, <span class="lg-highlight-string">"registered"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Debarge"</span>, <span class="lg-highlight-string">"registered"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Humphrey"</span>, <span class="lg-highlight-string">"registered"</span> <!-- -->: <span class="lg-highlight-literal">true</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The number of documents selected is different each time. If you need
to select an exact number of documents, consider using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sample/#mongodb-pipeline-pipe.-sample">
<code class="leafygreen-ui-1l06pbn">
$sample
</code>
</a>
instead of
<code class="leafygreen-ui-1l06pbn">
$rand
</code>
.
</p>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/rand/#mongodb-query-op.-rand">
<code class="leafygreen-ui-1l06pbn">
$rand (query)
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sample/#mongodb-pipeline-pipe.-sample">
<code class="leafygreen-ui-1l06pbn">
$sample
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/round/#mongodb-expression-exp.-round">
<code class="leafygreen-ui-1l06pbn">
$round
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$indexOfBytes (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-indexofbytes--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-indexofbytes--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-indexOfBytes" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-indexOfBytes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Searches a string for an occurrence of a substring and returns the
UTF-8 byte index (zero-based) of the first occurrence. If the
substring is not found, returns
<code class="leafygreen-ui-1l06pbn">
-1
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
has the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-agg-quick-ref-operator-expressions">
operator
expression syntax
<!-- -->
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $indexOfBytes: [ <string>, <substring>, <start>, <end> ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$indexOfBytes</span>: <!-- -->[ <!-- --><string expression>, <substring expression>, <start>, <end> ] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:30%"/>
<col style="width:65%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Operand
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
<string expression>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
as long as it resolves to a
string. For more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If the string expression resolves to a value of
<code class="leafygreen-ui-1l06pbn">
null
</code>
or
refers to a field that is missing,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If the string expression does not resolve to a string or
<code class="leafygreen-ui-1l06pbn">
null
</code>
nor
refers to a missing field,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns an error.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
<substring expression>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
as long as it resolves to a
string. For more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
<start>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<em>
Optional
</em>
An integral number that specifies the starting index
position for the search. Can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to
a non-negative integral number.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
<end>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<em>
Optional
</em>
An integral number that specifies the ending index
position for the search. Can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to
a non-negative integral number. If you specify a
<code class="leafygreen-ui-1l06pbn">
<end>
</code>
index
value, you should also specify a
<code class="leafygreen-ui-1l06pbn">
<start>
</code>
index value;
otherwise,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
uses the
<code class="leafygreen-ui-1l06pbn">
<end>
</code>
value as the
<code class="leafygreen-ui-1l06pbn">
<start>
</code>
index value instead of the
<code class="leafygreen-ui-1l06pbn">
<end>
</code>
value.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
<string expression>
</code>
is null,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
is called on a field that doesn't exist in the document,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
<string expression>
</code>
is not a string and not null,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns an error.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
<substring expression>
</code>
is null,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns an error.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
<start>
</code>
or
<code class="leafygreen-ui-1l06pbn">
<end>
</code>
is a negative number,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns an error.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
<start>
</code>
is a number greater than
<code class="leafygreen-ui-1l06pbn">
<end>
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
-1
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
<start>
</code>
is a number greater than the byte length of the string,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
-1
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
<start>
</code>
or
<code class="leafygreen-ui-1l06pbn">
<end>
</code>
is given a value that is not an integer,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns an error.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
<substring expression>
</code>
is found multiple times within the
<code class="leafygreen-ui-1l06pbn">
<string expression>
</code>
, then
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
returns the index of the first
<code class="leafygreen-ui-1l06pbn">
<substring expression>
</code>
found.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Some short examples to highlight different behavior:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:95%"/>
<col style="width:5%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Results
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "cafeteria", "e" ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
3
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "cafétéria", "é" ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
3
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "cafétéria", "e" ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
-1
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "cafétéria", "t" ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
5
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "foo.bar.fi", ".", 5 ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
7
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "vanilla", "ll", 0, 2 ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
-1
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "vanilla", "ll", -1 ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
-1
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "vanilla", "ll", 12 ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
-1
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "vanilla", "ll", 5, 2 ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
-1
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ "vanilla", "nilla", 3 ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
-1
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $indexOfBytes: [ null, "foo" ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
null
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider an
<code class="leafygreen-ui-1l06pbn">
inventory
</code>
collection with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"foo\" }\n{ \"_id\" : 2, \"item\" : \"fóofoo\" }\n{ \"_id\" : 3, \"item\" : \"the foo bar\" }\n{ \"_id\" : 4, \"item\" : \"hello world fóo\" }\n{ \"_id\" : 5, \"item\" : null }\n{ \"_id\" : 6, \"amount\" : 3 }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"foo"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"fóofoo"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"the foo bar"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"hello world fóo"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">3</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-indexOfBytes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$indexOfBytes
</code>
</span>
</a>
operator to
retrieve the indexes at which the string
<code class="leafygreen-ui-1l06pbn">
foo
</code>
is located in each item:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.aggregate(\n [\n {\n $project:\n {\n byteLocation: { $indexOfBytes: [ \"$item\", \"foo\" ] },\n }\n }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">byteLocation</span>: <!-- -->{ <span class="lg-highlight-attr">$indexOfBytes</span>: <!-- -->[ <span class="lg-highlight-string">"$item"</span>, <span class="lg-highlight-string">"foo"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following results:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"byteLocation\" : \"0\" }\n{ \"_id\" : 2, \"byteLocation\" : \"4\" }\n{ \"_id\" : 3, \"byteLocation\" : \"4\" }\n{ \"_id\" : 4, \"byteLocation\" : \"-1\" }\n{ \"_id\" : 5, \"byteLocation\" : null }\n{ \"_id\" : 6, \"byteLocation\" : null }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"byteLocation"</span> <!-- -->: <span class="lg-highlight-string">"0"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"byteLocation"</span> <!-- -->: <span class="lg-highlight-string">"4"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"byteLocation"</span> <!-- -->: <span class="lg-highlight-string">"4"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"byteLocation"</span> <!-- -->: <span class="lg-highlight-string">"-1"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"byteLocation"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"byteLocation"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/indexOfCP/#mongodb-expression-exp.-indexOfCP">
<code class="leafygreen-ui-1l06pbn">
$indexOfCP
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/indexOfArray/#mongodb-expression-exp.-indexOfArray">
<code class="leafygreen-ui-1l06pbn">
$indexOfArray
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/enforce-keyfile-access-control-in-existing-replica-set-without-downtime/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Update Self-Managed Replica Set to Keyfile Authentication (No Downtime)
<a class="headerlink leafygreen-ui-1kepx47" href="#update-self-managed-replica-set-to-keyfile-authentication--no-downtime-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-self-managed-replica-set-to-keyfile-authentication--no-downtime-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#enforce-keyfile-access-control-on-existing-replica-set" target="_self">
<span>
Enforce Keyfile Access Control on Existing Replica Set
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#x.509-internal-authentication" target="_self">
<span>
x.509 Internal Authentication
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To secure against unauthorized access, enforce
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
authentication
</a>
for your deployments. Authentication
for replica sets consists of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth">
internal authentication
</a>
among the replica set members, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
user access control
</a>
for clients connecting to the replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
If your deployment does not currently enforce authentication, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
--transitionToAuth
</code>
</a>
option to enforce
authentication without downtime.
</p>
<p class="leafygreen-ui-1kp3ins">
This tutorial uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-internal-auth-keyfile">
keyfile
</a>
internal
authentication mechanism for internal security, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-scram/#std-label-authentication-scram">
SCRAM
</a>
-based
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
role-based access controls
</a>
for client connections.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Cloud Manager and Ops Manager
<a class="headerlink leafygreen-ui-1kepx47" href="#cloud-manager-and-ops-manager" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="cloud-manager-and-ops-manager">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you are using Cloud Manager or Ops Manager to manage your deployment,
see the respective
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/cloud-manager/tutorial/edit-host-authentication-credentials/" target="_self">
<span>
Cloud Manager manual
</span>
</a>
or the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/ops-manager/current/tutorial/edit-host-authentication-credentials/" target="_self">
<span>
Ops Manager manual
</span>
</a>
to enforce authentication.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Architecture
<a class="headerlink leafygreen-ui-1kepx47" href="#architecture" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="architecture">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
This tutorial assumes that your replica set can elect a new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
after stepping down the existing primary replica set member.
This requires:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A majority of voting replica set members available after stepping down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
At least one
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
member that is not
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-delayed-member/#std-label-replica-set-delayed-members">
delayed
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-hidden-member/#std-label-replica-set-hidden-members">
hidden
</a>
,
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-priority-0-member/#std-label-replica-set-secondary-only-members">
Priority 0
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Transition State
<a class="headerlink leafygreen-ui-1kepx47" href="#transition-state" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="transition-state">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
--transitionToAuth
</code>
</a>
accepts both
authenticated and non-authenticated connections. Clients connected to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
during this transition state can perform read, write, and
administrative operations on any database.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Client Access
<a class="headerlink leafygreen-ui-1kepx47" href="#client-access" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="client-access">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
At the end of the following procedure, the replica set rejects any
client attempting to make a non-authenticated connection. The procedure creates
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-users/#std-label-users">
users
</a>
for client applications to use when connecting to the
replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist-role-based-access-control">
➤
<!-- -->
Configure Role-Based Access Control
</a>
for user creation and
management best practices.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
IP Binding
<a class="headerlink leafygreen-ui-1kepx47" href="#ip-binding" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ip-binding">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB binaries,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
, bind to
<code class="leafygreen-ui-1l06pbn">
localhost
</code>
by default.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Passwords
<a class="headerlink leafygreen-ui-1kepx47" href="#passwords" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="passwords">
</div>
</a>
</h3>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Passwords should be random, long, and complex to ensure system
security and to prevent or delay malicious access.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-security-replSet-nodowntime-enable-access-control">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Enforce Keyfile Access Control on Existing Replica Set
<a class="headerlink leafygreen-ui-1kepx47" href="#enforce-keyfile-access-control-on-existing-replica-set" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enforce-keyfile-access-control-on-existing-replica-set">
</div>
</a>
</h2>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To avoid configuration updates due to IP address changes, use DNS
hostnames instead of IP addresses. It is particularly important to
use a DNS hostname instead of an IP address when configuring replica
set members or sharded cluster members.
</p>
<p class="leafygreen-ui-1kp3ins">
Use hostnames instead of IP addresses to configure clusters across a
split network horizon. Starting in MongoDB 5.0, nodes that are only
configured with an IP address fail startup validation and do not start.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create the user administrator.Connect to the primary to create a user with\nuserAdminAnyDatabase role. The\nuserAdminAnyDatabase role grants access to user creation\non any database in the deployment.The following example creates the user fred with the\nuserAdminAnyDatabase role on the admin database.Passwords should be random, long, and complex to ensure system\nsecurity and to prevent or delay malicious access.You can use the passwordPrompt() method in conjunction with\nvarious user authentication management methods and commands to prompt\nfor the password instead of specifying the password directly in the\nmethod or command call. However, you can still specify the password\ndirectly as you would with earlier versions of the\nmongo shell.At the completion of this procedure, any client that administers users in\nthe replica set must authenticate as this user, or a user with\nsimilar permissions.See Database User Roles for a full list of built-in roles and\nrelated to database administration operations."},{"@type":"HowToStep","text":"Create the cluster administrator.Connect to the primary to create a user with\nclusterAdmin role. The clusterAdmin role\ngrants access to replication operations, such as configuring the\nreplica set.The following example creates the user ravi with the\nclusterAdmin role on the admin database.Passwords should be random, long, and complex to ensure system security\nand to prevent or delay malicious access.You can use the passwordPrompt() method in conjunction with\nvarious user authentication management methods and commands to prompt\nfor the password instead of specifying the password directly in the\nmethod or command call. However, you can still specify the password\ndirectly as you would with earlier versions of the\nmongo shell.At the completion of this procedure, any client that administrates or\nmaintains the replica set must authenticate as this user, or a user with\nsimilar permissions.See Cluster Administration Roles for a full list of built-in roles related to\nreplica set operations."},{"@type":"HowToStep","text":"Create users for client applications.Create users to allow client application to connect and interact with the\nreplica set. At the completion of this tutorial, clients must authenticate as\na configured user to connect to the replica set.See Database User Roles for basic built-in roles to use\nin creating read-only and read-write users.The following creates a user with read and write permissions\non the foo database.Passwords should be random, long, and complex to ensure system security\nand to prevent or delay malicious access.Create a user with the\nreadWrite role in the foo database.You can use the passwordPrompt() method in conjunction with\nvarious user authentication management methods and commands to prompt\nfor the password instead of specifying the password directly in the\nmethod or command call. However, you can still specify the password\ndirectly as you would with earlier versions of the\nmongo shell.Clients authenticating as this user can perform read and write operations\nagainst the foo database. See Authenticate a User with Self-Managed Deployments for\nmore on creating an authenticated connection to the replica set.See the Add Users tutorial for more information on\nadding users. Consider security best practices when adding new users."},{"@type":"HowToStep","text":"Update Client ApplicationsAt this point in the procedure, the replica set does not enforce\nauthentication. However, client applications can still specify auth\ncredentials and connect to the replica set.Update client applications to authenticate to the replica set using a\nconfigured user. Authenticated connections require a username, password, and\nthe authentication database. See Authenticate a User with Self-Managed Deployments.For example, the following connects to a replica set named mongoRepl\nand authenticates as the user joe.If you do not specify the password to the -p\ncommand-line option, mongosh prompts for the\npassword.If your application uses a MongoDB driver, see the associated\ndriver documentation for instructions on\ncreating an authenticated connection.At the completion of this tutorial, the replica set rejects non-authenticated\nclient connections. Performing this step now ensures clients can connect\nto the replica set before and after the transition."},{"@type":"HowToStep","text":"Create a keyfile.With keyfile authentication, each\nmongod instances in the replica set uses the contents of the keyfile as the\nshared password for authenticating other members in the deployment. Only\nmongod instances with the correct keyfile can join the replica set.Keyfiles for internal membership authentication use YAML format to allow for multiple keys in a\nkeyfile. The YAML format accepts either:A single key string (same as in earlier versions)A sequence of key stringsThe YAML format is compatible with the existing single-key\nkeyfiles that use the text file format.A key's length must be between 6 and 1024 characters and may only\ncontain characters in the base64 set. All members of the\nreplica set must share at least one common key.On UNIX systems, the keyfile must not have group or world\npermissions. On Windows systems, keyfile permissions are not checked.You can generate a keyfile using any method you choose. For example,\nthe following operation uses openssl to generate a complex\npseudo-random 1024 character string to use as a shared password. It then\nuses chmod to change file permissions to provide read\npermissions for the file owner only:See Keyfiles for additional details and requirements\nfor using keyfiles."},{"@type":"HowToStep","text":"Copy the keyfile to each replica set member.Copy the keyfile to each server hosting the replica set members.\nEnsure that the user running the mongod instances is the owner of the\nfile and can access the keyfile.Avoid storing the keyfile on storage mediums that can be easily\ndisconnected from the hardware hosting the mongod instances, such as a\nUSB drive or a network attached storage device."},{"@type":"HowToStep","text":"Restart each secondary or arbiter member of the replica set with transitionToAuth.Restart each secondary or arbiter member in the\nreplica set, including in the configuration:The security.transitionToAuth setting. Starting the\nmongod with security.transitionToAuth set to\ntrue places the instance in a transition state where it can\naccept and create both authenticated and non-authenticated\nconnections.An internal authentication mechanism such as\nsecurity.keyFile.You must restart each member one at a time to ensure a majority of\nmembers in the replica set remain online.Shut down the secondary or arbiter members.From a mongosh session that is connected to the\nsecondary or arbiter, issue the db.shutdownServer()\nagainst the admin database.Restart the secondary or arbiter members with transitionToAuthSpecify the following settings in your configuration file.security.keyFile, with the path to the keyfile.replication.replSetName to the original replica set name.security.transitionToAuth to true.mongod and mongos\nbind to localhost by default. If the members of your deployment are\nrun on different hosts or if you wish remote clients to connect to\nyour deployment, you must specify the net.bindIp setting.Specify the --config option with the path to the configuration\nfile when starting the mongod.For more information on the configuration file, see\nconfiguration options.Alternatively, you can use the equivalent mongod\ncommand-line options (e.g. --transitionToAuth and\n--keyFile) when starting your mongod. See the\nmongod reference page for a complete list of options.Include additional settings as appropriate to your deployment.At the end of this step, all secondaries and arbiters should be up\nand running with security.transitionToAuth set to true."},{"@type":"HowToStep","text":"Step down the primary member of the replica set and restart it with --transitionToAuth.Step down the primary member in the replica set and restart\nthe member, including in its configuration:The security.transitionToAuth setting. Starting the\nmongod with security.transitionToAuth set to\ntrue places the instance in a transition state where it can\naccept and create both authenticated and non-authenticated\nconnections.An internal authentication mechanism such as\nsecurity.keyFile.Step down the primary replica set memberConnect to the primary using mongosh and step down\nthe primary using the rs.stepDown() method.Shut down the old primaryOnce the primary steps down and the replica set elects a new primary,\nshut down the old primary mongod.From a mongosh session that is connected to the old\nprimary, issue the db.shutdownServer() on the admin\ndatabase.Restart the old primary with transitionToAuthSpecify the following settings in your configuration file.security.keyFile, with the path to the keyfile.replication.replSetName to the original replica set name.security.transitionToAuth to true.Include additional options as required\nfor your configuration. For instance, if you wish remote clients to\nconnect to your deployment or your deployment members are run on\ndifferent hosts, specify the net.bindIp setting.Start the mongod using the configuration file.For more information on the configuration file, see\nconfiguration options.Alternatively, you can use the equivalent mongod\ncommand-line options (e.g. --transitionToAuth and\n--keyFile) when starting your mongod. See the\nmongod reference page for a complete list of options.Include additional settings as appropriate to your deployment.At the end of this step, all members of the replica set should be up\nand running with security.transitionToAuth set to true\nand security.keyFile set to the keyfile path."},{"@type":"HowToStep","text":"Restart secondaries and arbiters without --transitionToAuthRestart each secondary or arbiter member in the replica set,\nremoving the security.transitionToAuth option on restart. You must do\nthis one at a time to ensure a majority of members in the replica set remain\nonline.If the majority of replica set members are offline at the same time, the\nreplica set may go into read-only mode.Shut down the secondary or arbiter membersConnect mongosh to the secondary or arbiter, and\nissue the db.shutdownServer() on the admin database.Restart the secondary or arbiter members without transitionToAuthRestart the mongod, this time without the\nsecurity.transitionToAuth option but with internal authentication\nmechanism such as security.keyFile.Specify the following settings in your configuration file.security.keyFile, with the path to the keyfile.replication.replSetName to the original replica set name.Include additional options as required\nfor your configuration. For instance, if you wish remote clients to\nconnect to your deployment or your deployment members are run on\ndifferent hosts, specify the net.bindIp setting.Start the mongod using the configuration file:For more information on the configuration file, see\nconfiguration options.You can also use the equivalent mongod options when starting your\nmongod. See the mongod reference page for a complete list of\noptions.Include additional settings as appropriate to your deployment.At the end of this step, all secondaries and arbiters should be up and\nrunning with internal authentication configured, but without\nsecurity.transitionToAuth. Clients can only connect to these\nmongod instances by using the configured client authentication\nmechanism."},{"@type":"HowToStep","text":"Step down and restart the primary replica set member without --transitionToAuth.Step down the primary member in the replica set, then restart it\nwithout the security.transitionToAuth option.At the end of this step, clients not connecting with auth cannot connect\nto the replica set. Update clients to connect with authentication before\ncompleting this step to avoid loss of connectivity.Step down the primary replica set memberConnect to the primary using mongosh and step down\nthe primary using the rs.stepDown() method.Shut down the old primaryOnce the primary steps down and the replica set elects a new primary,\nshut down the old primary mongod.From a mongosh session that is connected to the old\nprimary, issue the db.shutdownServer() on the admin\ndatabase.Restart the old primary without transitionToAuthRestart the mongod, this time without the\nsecurity.transitionToAuth option but with the internal authentication\nmechanism such as security.keyFile.Specify the following settings in your configuration file.security.keyFile, with the path to the keyfile.replication.replSetName to the original replica set name.Start the mongod using the configuration file:For more information on the configuration file, see\nconfiguration options.You can also use the equivalent mongod options when starting your\nmongod. See the mongod reference page for a complete list of\noptions.Include additional settings as appropriate to your deployment.At the end of this step, all members of the replica set should be up and\nrunning with authentication enforced. Clients can only connect to these\nmongod instances by using the configured client authentication\nmechanism."}],"name":"Enforce Keyfile Access Control on Existing Replica Set","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create the user administrator.
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-user-administrator" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-the-user-administrator">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Connect to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
to create a user with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-userAdminAnyDatabase">
<code class="leafygreen-ui-1l06pbn">
userAdminAnyDatabase
</code>
</a>
role. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-userAdminAnyDatabase">
<code class="leafygreen-ui-1l06pbn">
userAdminAnyDatabase
</code>
</a>
role grants access to user creation
on any database in the deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example creates the user
<code class="leafygreen-ui-1l06pbn">
fred
</code>
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-userAdminAnyDatabase">
<code class="leafygreen-ui-1l06pbn">
userAdminAnyDatabase
</code>
</a>
role on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Passwords should be random, long, and complex to ensure system
security and to prevent or delay malicious access.
</p>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
You can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/passwordPrompt/#mongodb-method-passwordPrompt">
<code class="leafygreen-ui-1l06pbn">
passwordPrompt()
</code>
</a>
method in conjunction with
various user authentication management methods and commands to prompt
for the password instead of specifying the password directly in the
method or command call. However, you can still specify the password
directly as you would with earlier versions of the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.createUser(\n {\n user: \"fred\",\n pwd: \" passwordPrompt(), // or cleartext password\n roles: [ { role: \"userAdminAnyDatabase\", db: \"admin\" } ]\n }\n)\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">admin <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">admin.<span class="lg-highlight-title lg-highlight-function">createUser</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"fred"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pwd</span>: <span class="lg-highlight-string">" passwordPrompt(), // or cleartext password</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> roles: [ { role: "</span>userAdminAnyDatabase<span class="lg-highlight-string">", db: "</span>admin<span class="lg-highlight-string">" } ]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"> }</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">)</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string"></span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
At the completion of this procedure, any client that administers users in
the replica set must authenticate as this user, or a user with
similar permissions.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#std-label-database-user-roles">
Database User Roles
</a>
for a full list of built-in roles and
related to database administration operations.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create the cluster administrator.
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-cluster-administrator" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-the-cluster-administrator">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Connect to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
to create a user with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin">
<code class="leafygreen-ui-1l06pbn">
clusterAdmin
</code>
</a>
role. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin">
<code class="leafygreen-ui-1l06pbn">
clusterAdmin
</code>
</a>
role
grants access to replication operations, such as configuring the
replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example creates the user
<code class="leafygreen-ui-1l06pbn">
ravi
</code>
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin">
<code class="leafygreen-ui-1l06pbn">
clusterAdmin
</code>
</a>
role on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Passwords should be random, long, and complex to ensure system security
and to prevent or delay malicious access.
</p>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
You can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/passwordPrompt/#mongodb-method-passwordPrompt">
<code class="leafygreen-ui-1l06pbn">
passwordPrompt()
</code>
</a>
method in conjunction with
various user authentication management methods and commands to prompt
for the password instead of specifying the password directly in the
method or command call. However, you can still specify the password
directly as you would with earlier versions of the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").createUser(\n {\n \"user\" : \"ravi\",\n \"pwd\" : passwordPrompt(), // or cleartext password\n roles: [ { \"role\" : \"clusterAdmin\", \"db\" : \"admin\" } ] \n }\n)\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>).<span class="lg-highlight-title lg-highlight-function">createUser</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"user"</span> <!-- -->: <span class="lg-highlight-string">"ravi"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pwd"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">passwordPrompt</span>(<!-- -->)<!-- -->, <span class="lg-highlight-comment">// or cleartext password</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">roles</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"role"</span> <!-- -->: <span class="lg-highlight-string">"clusterAdmin"</span>, <span class="lg-highlight-string">"db"</span> <!-- -->: <span class="lg-highlight-string">"admin"</span> } ] </td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
At the completion of this procedure, any client that administrates or
maintains the replica set must authenticate as this user, or a user with
similar permissions.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#std-label-cluster-admin-roles">
Cluster Administration Roles
</a>
for a full list of built-in roles related to
replica set operations.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create users for client applications.
<a class="headerlink leafygreen-ui-1kepx47" href="#create-users-for-client-applications" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-users-for-client-applications">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create users to allow client application to connect and interact with the
replica set. At the completion of this tutorial, clients must authenticate as
a configured user to connect to the replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#std-label-database-user-roles">
Database User Roles
</a>
for basic built-in roles to use
in creating read-only and read-write users.
</p>
<p class="leafygreen-ui-1kp3ins">
The following creates a user with read and write permissions
on the
<code class="leafygreen-ui-1l06pbn">
foo
</code>
database.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Passwords should be random, long, and complex to ensure system security
and to prevent or delay malicious access.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a user with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-readWrite">
<code class="leafygreen-ui-1l06pbn">
readWrite
</code>
</a>
role in the
<code class="leafygreen-ui-1l06pbn">
foo
</code>
database.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
You can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/passwordPrompt/#mongodb-method-passwordPrompt">
<code class="leafygreen-ui-1l06pbn">
passwordPrompt()
</code>
</a>
method in conjunction with
various user authentication management methods and commands to prompt
for the password instead of specifying the password directly in the
method or command call. However, you can still specify the password
directly as you would with earlier versions of the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"foo\").createUser(\n {\n \"user\" : \"joe\",\n \"pwd\" : passwordPrompt(), // or cleartext password\n roles: [ { \"role\" : \"readWrite\", \"db\" : \"foo\" } ] \n }\n)\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"foo"</span>).<span class="lg-highlight-title lg-highlight-function">createUser</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"user"</span> <!-- -->: <span class="lg-highlight-string">"joe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pwd"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">passwordPrompt</span>(<!-- -->)<!-- -->, <span class="lg-highlight-comment">// or cleartext password</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">roles</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"role"</span> <!-- -->: <span class="lg-highlight-string">"readWrite"</span>, <span class="lg-highlight-string">"db"</span> <!-- -->: <span class="lg-highlight-string">"foo"</span> } ] </td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Clients authenticating as this user can perform read and write operations
against the
<code class="leafygreen-ui-1l06pbn">
foo
</code>
database. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/authenticate-a-user/#std-label-authentication-auth-as-user">
Authenticate a User with Self-Managed Deployments
</a>
for
more on creating an authenticated connection to the replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/create-users/#std-label-add-new-user">
Add Users
</a>
tutorial for more information on
adding users. Consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist-role-based-access-control">
security best practices
</a>
when adding new users.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update Client Applications
<a class="headerlink leafygreen-ui-1kepx47" href="#update-client-applications" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-client-applications">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
At this point in the procedure, the replica set does not enforce
authentication. However, client applications can still specify auth
credentials and connect to the replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
Update client applications to authenticate to the replica set using a
configured user. Authenticated connections require a username, password, and
the authentication database. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/authenticate-a-user/#std-label-authentication-auth-as-user">
Authenticate a User with Self-Managed Deployments
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following connects to a replica set named
<code class="leafygreen-ui-1l06pbn">
mongoRepl
</code>
and authenticates as the user
<code class="leafygreen-ui-1l06pbn">
joe
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongosh -u joe -password -authenticationDatabase foo --host mongoRepl/mongo1.example.net:27017, mongo2.example.net:27017, mongo3.example.net:27017\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh -u joe -password -authenticationDatabase foo --host mongoRepl/mongo1.example.net:27017, mongo2.example.net:27017, mongo3.example.net:27017</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you do not specify the password to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/options/#std-option-mongosh.--password" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
-p
</code>
</span>
</a>
command-line option,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
prompts for the
password.
</p>
<p class="leafygreen-ui-1kp3ins">
If your application uses a MongoDB driver, see the associated
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver
</span>
</a>
documentation for instructions on
creating an authenticated connection.
</p>
<p class="leafygreen-ui-1kp3ins">
At the completion of this tutorial, the replica set rejects non-authenticated
client connections. Performing this step now ensures clients can connect
to the replica set before and after the transition.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
5
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create a keyfile.
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-keyfile" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-a-keyfile">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
With
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-internal-auth-keyfile">
keyfile
</a>
authentication, each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances in the replica set uses the contents of the keyfile as the
shared password for authenticating other members in the deployment. Only
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances with the correct keyfile can join the replica set.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-internal-auth-keyfile">
Keyfiles for internal membership authentication
</a>
use YAML format to allow for multiple keys in a
keyfile. The YAML format accepts either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A single key string (same as in earlier versions)
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A sequence of key strings
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The YAML format is compatible with the existing single-key
keyfiles that use the text file format.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
A key's length must be between 6 and 1024 characters and may only
contain characters in the base64 set. All members of the
replica set must share at least one common key.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
On UNIX systems, the keyfile must not have group or world
permissions. On Windows systems, keyfile permissions are not checked.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can generate a keyfile using any method you choose. For example,
the following operation uses
<code class="leafygreen-ui-1l06pbn">
openssl
</code>
to generate a complex
pseudo-random 1024 character string to use as a shared password. It then
uses
<code class="leafygreen-ui-1l06pbn">
chmod
</code>
to change file permissions to provide read
permissions for the file owner only:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"openssl rand -base64 756 > <path-to-keyfile>\nchmod 400 <path-to-keyfile>\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">openssl rand -base64 756 > <path-to-keyfile></td></tr><tr class=""><td class="leafygreen-ui-7razhx">chmod 400 <path-to-keyfile></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-internal-auth-keyfile">
Keyfiles
</a>
for additional details and requirements
for using keyfiles.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
6
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Copy the keyfile to each replica set member.
<a class="headerlink leafygreen-ui-1kepx47" href="#copy-the-keyfile-to-each-replica-set-member" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="copy-the-keyfile-to-each-replica-set-member">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Copy the keyfile to each server hosting the replica set members.
Ensure that the user running the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances is the owner of the
file and can access the keyfile.
</p>
<p class="leafygreen-ui-1kp3ins">
Avoid storing the keyfile on storage mediums that can be easily
disconnected from the hardware hosting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances, such as a
USB drive or a network attached storage device.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
7
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Restart each secondary or arbiter member of the replica set with
<code class="leafygreen-ui-1l06pbn">
transitionToAuth
</code>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-each-secondary-or-arbiter-member-of-the-replica-set-with-transitiontoauth" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-each-secondary-or-arbiter-member-of-the-replica-set-with-transitiontoauth">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Restart each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-arbiter">
arbiter
</a>
member in the
replica set, including in the configuration:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
setting. Starting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
places the instance in a transition state where it can
accept and create both authenticated and non-authenticated
connections.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
An internal authentication mechanism such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You must restart each member one at a time to ensure a majority of
members in the replica set remain online.
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Shut down the secondary or arbiter members.
<a class="headerlink leafygreen-ui-1kepx47" href="#shut-down-the-secondary-or-arbiter-members" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shut-down-the-secondary-or-arbiter-members">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
From a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
session that is connected to the
secondary or arbiter, issue the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.shutdownServer/#mongodb-method-db.shutdownServer">
<code class="leafygreen-ui-1l06pbn">
db.shutdownServer()
</code>
</a>
against the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.shutdownServer()\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">admin <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">admin.<span class="lg-highlight-title lg-highlight-function">shutdownServer</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Restart the secondary or arbiter members with
<code class="leafygreen-ui-1l06pbn">
transitionToAuth
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-the-secondary-or-arbiter-members-with-transitiontoauth" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-the-secondary-or-arbiter-members-with-transitiontoauth">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Specify the following settings in your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/configuration/#std-label-configuration-file">
configuration file
<!-- -->
.
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
</a>
, with the path to the keyfile.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
to the original replica set name.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
bind to localhost by default. If the members of your deployment are
run on different hosts or if you wish remote clients to connect to
your deployment, you must specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</a>
setting.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n keyFile: <path-to-keyfile>\n transitionToAuth: true\nreplication:\n replSetName: <replicasetname>\n","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">security:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyFile:</span> <span class="lg-highlight-string"><path-to-keyfile></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transitionToAuth:</span> <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSetName:</span> <span class="lg-highlight-string"><replicaSetName></span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<p class="leafygreen-ui-1kp3ins">
Specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--config">
<code class="leafygreen-ui-1l06pbn">
--config
</code>
</a>
option with the path to the configuration
file when starting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --config <path-to-config-file>\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --config <path-to-config-file></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on the configuration file, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
configuration options
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Alternatively, you can use the equivalent
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
command-line options (e.g.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
--transitionToAuth
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--keyFile">
<code class="leafygreen-ui-1l06pbn">
--keyFile
</code>
</a>
) when starting your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
reference page for a complete list of options.
</p>
<p class="leafygreen-ui-1kp3ins">
Include additional settings as appropriate to your deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
At the end of this step, all secondaries and arbiters should be up
and running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
8
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Step down the primary member of the replica set and restart it with
<code class="leafygreen-ui-1l06pbn">
--transitionToAuth
</code>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#step-down-the-primary-member-of-the-replica-set-and-restart-it-with-transitiontoauth" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="step-down-the-primary-member-of-the-replica-set-and-restart-it-with-transitiontoauth">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Step down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
member in the replica set and restart
the member, including in its configuration:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
setting. Starting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
places the instance in a transition state where it can
accept and create both authenticated and non-authenticated
connections.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
An internal authentication mechanism such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
.
</a>
</p>
</li>
</ul>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Step down the primary replica set member
<a class="headerlink leafygreen-ui-1kepx47" href="#step-down-the-primary-replica-set-member" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="step-down-the-primary-replica-set-member">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Connect to the primary using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
and step down
the primary using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.stepDown/#mongodb-method-rs.stepDown">
<code class="leafygreen-ui-1l06pbn">
rs.stepDown()
</code>
</a>
method.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"rs.stepDown()\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">rs.<span class="lg-highlight-title lg-highlight-function">stepDown</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Shut down the old primary
<a class="headerlink leafygreen-ui-1kepx47" href="#shut-down-the-old-primary" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shut-down-the-old-primary">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Once the primary steps down and the replica set elects a new primary,
shut down the old primary
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
From a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
session that is connected to the old
primary, issue the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.shutdownServer/#mongodb-method-db.shutdownServer">
<code class="leafygreen-ui-1l06pbn">
db.shutdownServer()
</code>
</a>
on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.shutdownServer()\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">admin <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">admin.<span class="lg-highlight-title lg-highlight-function">shutdownServer</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Restart the old primary with
<code class="leafygreen-ui-1l06pbn">
transitionToAuth
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-the-old-primary-with-transitiontoauth" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-the-old-primary-with-transitiontoauth">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Specify the following settings in your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/configuration/#std-label-configuration-file">
configuration file
<!-- -->
.
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
</a>
, with the path to the keyfile.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
to the original replica set name.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Include additional options as required
for your configuration. For instance, if you wish remote clients to
connect to your deployment or your deployment members are run on
different hosts, specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</a>
setting.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n keyFile: <path-to-keyfile>\n transitionToAuth: true\nreplication:\n replSetName: <replicasetname>\n \n","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">security:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyFile:</span> <span class="lg-highlight-string"><path-to-keyfile></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transitionToAuth:</span> <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSetName:</span> <span class="lg-highlight-string"><replicaSetName></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> </td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<p class="leafygreen-ui-1kp3ins">
Start the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
using the configuration file.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --config <path-to-config-file>\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --config <path-to-config-file></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on the configuration file, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
configuration options
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Alternatively, you can use the equivalent
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
command-line options (e.g.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
--transitionToAuth
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--keyFile">
<code class="leafygreen-ui-1l06pbn">
--keyFile
</code>
</a>
) when starting your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
reference page for a complete list of options.
</p>
<p class="leafygreen-ui-1kp3ins">
Include additional settings as appropriate to your deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
At the end of this step, all members of the replica set should be up
and running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
</a>
set to the keyfile path.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
9
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Restart secondaries and arbiters
<em>
without
</em>
<code class="leafygreen-ui-1l06pbn">
--transitionToAuth
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-secondaries-and-arbiters-without-transitiontoauth" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-secondaries-and-arbiters-without-transitiontoauth">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Restart each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-arbiter">
arbiter
</a>
member in the replica set,
removing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
option on restart. You must do
this one at a time to ensure a majority of members in the replica set remain
online.
</p>
<p class="leafygreen-ui-1kp3ins">
If the majority of replica set members are offline at the same time, the
replica set may go into read-only mode.
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Shut down the secondary or arbiter members
<a class="headerlink leafygreen-ui-1kepx47" href="#shut-down-the-secondary-or-arbiter-members-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shut-down-the-secondary-or-arbiter-members-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to the secondary or arbiter, and
issue the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.shutdownServer/#mongodb-method-db.shutdownServer">
<code class="leafygreen-ui-1l06pbn">
db.shutdownServer()
</code>
</a>
on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.shutdownServer()\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">admin <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">admin.<span class="lg-highlight-title lg-highlight-function">shutdownServer</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Restart the secondary or arbiter members without
<code class="leafygreen-ui-1l06pbn">
transitionToAuth
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-the-secondary-or-arbiter-members-without-transitiontoauth" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-the-secondary-or-arbiter-members-without-transitiontoauth">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Restart the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
, this time
<em>
without
</em>
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
option but
<em>
with
</em>
internal authentication
mechanism such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Specify the following settings in your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/configuration/#std-label-configuration-file">
configuration file
<!-- -->
.
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
</a>
, with the path to the keyfile.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
to the original replica set name.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Include additional options as required
for your configuration. For instance, if you wish remote clients to
connect to your deployment or your deployment members are run on
different hosts, specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</a>
setting.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n keyFile: <path-to-keyfile>\nreplication:\n replSetName: <replicasetname>\n","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">security:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyFile:</span> <span class="lg-highlight-string"><path-to-keyfile></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSetName:</span> <span class="lg-highlight-string"><replicaSetName></span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<p class="leafygreen-ui-1kp3ins">
Start the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
using the configuration file:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --config <path-to-config-file>\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --config <path-to-config-file></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on the configuration file, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
configuration options
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You can also use the equivalent
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
options when starting your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
reference page for a complete list of
options.
</p>
<p class="leafygreen-ui-1kp3ins">
Include additional settings as appropriate to your deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
At the end of this step, all secondaries and arbiters should be up and
running with internal authentication configured, but
<em>
without
</em>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
. Clients can only connect to these
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances by using the configured client authentication
mechanism.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
10
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Step down and restart the primary replica set member
<em>
without
</em>
<code class="leafygreen-ui-1l06pbn">
--transitionToAuth
</code>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#step-down-and-restart-the-primary-replica-set-member-without-transitiontoauth" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="step-down-and-restart-the-primary-replica-set-member-without-transitiontoauth">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Step down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
member in the replica set, then restart it
without the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
option.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
At the end of this step, clients not connecting with auth cannot connect
to the replica set. Update clients to connect with authentication
<em>
before
</em>
completing this step to avoid loss of connectivity.
</p>
</div>
</div>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Step down the primary replica set member
<a class="headerlink leafygreen-ui-1kepx47" href="#step-down-the-primary-replica-set-member-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="step-down-the-primary-replica-set-member-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Connect to the primary using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
and step down
the primary using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.stepDown/#mongodb-method-rs.stepDown">
<code class="leafygreen-ui-1l06pbn">
rs.stepDown()
</code>
</a>
method.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"rs.stepDown()\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">rs.<span class="lg-highlight-title lg-highlight-function">stepDown</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Shut down the old primary
<a class="headerlink leafygreen-ui-1kepx47" href="#shut-down-the-old-primary-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shut-down-the-old-primary-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Once the primary steps down and the replica set elects a new primary,
shut down the old primary
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
From a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
session that is connected to the old
primary, issue the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.shutdownServer/#mongodb-method-db.shutdownServer">
<code class="leafygreen-ui-1l06pbn">
db.shutdownServer()
</code>
</a>
on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.shutdownServer()\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">admin <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">admin.<span class="lg-highlight-title lg-highlight-function">shutdownServer</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Restart the old primary without
<code class="leafygreen-ui-1l06pbn">
transitionToAuth
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-the-old-primary-without-transitiontoauth" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-the-old-primary-without-transitiontoauth">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Restart the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
, this time
<em>
without
</em>
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.transitionToAuth">
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</a>
option but
<em>
with
</em>
the internal authentication
mechanism such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Specify the following settings in your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/configuration/#std-label-configuration-file">
configuration file
<!-- -->
.
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.keyFile">
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
</a>
, with the path to the keyfile.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
to the original replica set name.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n keyFile: <path-to-keyfile>\nreplication:\n replSetName: <replicasetname>\n \n","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">security:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyFile:</span> <span class="lg-highlight-string"><path-to-keyfile></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSetName:</span> <span class="lg-highlight-string"><replicaSetName></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> </td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<p class="leafygreen-ui-1kp3ins">
Start the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
using the configuration file:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --config <path-to-config-file>\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --config <path-to-config-file></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on the configuration file, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
configuration options
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You can also use the equivalent
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
options when starting your
mongod. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
reference page for a complete list of
options.
</p>
<p class="leafygreen-ui-1kp3ins">
Include additional settings as appropriate to your deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
At the end of this step, all members of the replica set should be up and
running with authentication enforced. Clients can only connect to these
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances by using the configured client authentication
mechanism.
</p>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
x.509 Internal Authentication
<a class="headerlink leafygreen-ui-1kepx47" href="#x.509-internal-authentication" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="x.509-internal-authentication">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For details on using x.509 for internal authentication, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-x509-member-authentication/">
Use x.509 Certificate for Membership Authentication with Self-Managed MongoDB
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To upgrade from keyfile internal authentication to x.509 internal
authentication, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/upgrade-keyfile-to-x509/">
Upgrade Self-Managed MongoDB from Keyfile Authentication to x.509 Authentication
<!-- -->
.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/cursor.readPref/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
cursor.readPref()
<a class="headerlink leafygreen-ui-1kepx47" href="#cursor.readpref--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="cursor.readpref--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
cursor.readPref(mode, tagSet, hedgeOptions)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.readPref" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-cursor.readPref">
</div>
</a>
</dt>
<dd>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for a language-specific driver, such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Append
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.readPref" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
readPref()
</code>
</span>
</a>
to a cursor to
control how the client routes the query to members
of the replica set.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
You must apply
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.readPref" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
readPref()
</code>
</span>
</a>
to the cursor before retrieving
any documents from the database.
</p>
</div>
</div>
</dd>
</dl>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#parameters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="parameters">
</div>
</a>
</h3>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Parameter
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cursor-readpref-mode" target="_self">
<span>
mode
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cursor-readpref-mode">
</span>
<p class="leafygreen-ui-1kp3ins">
One of the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-read-preference">
read preference
</a>
modes:
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primary">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primaryPreferred">
<code class="leafygreen-ui-1l06pbn">
primaryPreferred
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondaryPreferred">
<code class="leafygreen-ui-1l06pbn">
secondaryPreferred
</code>
</a>
, or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-nearest">
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cursor-readpref-tagset" target="_self">
<span>
tagSet
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
array of documents
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cursor-readpref-tagset">
</span>
<p class="leafygreen-ui-1kp3ins">
Optional. A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
tag set
</a>
used to target reads to
members with the specified tag(s).
<code class="leafygreen-ui-1l06pbn">
tagSet
</code>
is not available
if using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primary">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
Read Preference Tag Set Lists
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cursor-readpref-hedge" target="_self">
<span>
hedgeOptions
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cursor-readpref-hedge">
</span>
<p class="leafygreen-ui-1kp3ins">
<strong class="css-rws738">
IMPORTANT:
</strong>
Starting in MongoDB 8.0, hedged reads are
deprecated. Queries that specify the read preference
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-nearest">
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
</a>
no longer use hedged reads by default. If you
explicitly specify a hedged read, MongoDB performs a hedged read
and logs a warning.
</p>
<p class="leafygreen-ui-1kp3ins">
Optional. A document that specifies whether to enable the use of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-mongos-hedged-reads">
hedged reads
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ enabled: <boolean> }
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
enabled
</code>
field defaults to true; i.e. specifying an empty
document
<code class="leafygreen-ui-1l06pbn">
{ }
</code>
is equivalent to specifying
<code class="leafygreen-ui-1l06pbn">
{ enabled: true
}
</code>
.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.readPref" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
readPref()
</code>
</span>
</a>
does not support the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
Read Preference
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
</a>
option for read
preference.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Specify Read Preference Mode
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-read-preference-mode" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="specify-read-preference-mode">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following operation uses the read preference
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cursor-readpref-mode" target="_self">
<span>
mode
</span>
</a>
to target the read to a secondary member.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find({ }).readPref( \"secondary\")","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->{ <!-- -->}).<span class="lg-highlight-title lg-highlight-function">readPref</span>( <span class="lg-highlight-string">"secondary"</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Specify Read Preference Tag Set
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-read-preference-tag-set" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="specify-read-preference-tag-set">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To target secondaries with specific tags, include both the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cursor-readpref-mode" target="_self">
<span>
mode
</span>
</a>
and the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cursor-readpref-tagset" target="_self">
<span>
tagSet
</span>
</a>
array:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find({ }).readPref(\n \"secondary\",\n [\n { \"datacenter\": \"B\" }, // First, try matching by the datacenter tag\n { \"region\": \"West\"}, // If not found, then try matching by the region tag\n { } // If not found, then use the empty document to match all eligible members\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->{ <!-- -->}).<span class="lg-highlight-title lg-highlight-function">readPref</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondary"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"datacenter"</span>: <span class="lg-highlight-string">"B"</span> }<!-- -->, <span class="lg-highlight-comment">// First, try matching by the datacenter tag</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"region"</span>: <span class="lg-highlight-string">"West"</span>}<!-- -->, <span class="lg-highlight-comment">// If not found,</span><span class="lg-highlight-comment"> then try matching </span><span class="lg-highlight-comment">by the region tag</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->} <span class="lg-highlight-comment">// If not found,</span><span class="lg-highlight-comment"> then use the </span><span class="lg-highlight-comment">empty</span><span class="lg-highlight-comment"> document to match </span><span class="lg-highlight-comment">all eligible members</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
During the secondary selection process, MongoDB tries to find secondary
members with the
<code class="leafygreen-ui-1l06pbn">
datacenter: "B"
</code>
tag first.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If found, MongoDB limits the eligible secondaries to those with the
<code class="leafygreen-ui-1l06pbn">
datacenter: "B"
</code>
tag and ignores the remaining tags.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If none are found, then, MongoDB tries to find secondary members with
the
<code class="leafygreen-ui-1l06pbn">
"region": "West"
</code>
tag.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If found, MongoDB limits the eligible secondaries to those with the
<code class="leafygreen-ui-1l06pbn">
"region": "West"
</code>
tag.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If none are found, MongoDB uses any eligible secondaries.
</p>
</li>
</ul>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-read-pref-order-matching">
Order of Tag Matching
</a>
for details.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-replica-set-tag-sets/">
Configure Replica Set Tag Sets
</a>
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Specify Hedged Read
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-hedged-read" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="specify-hedged-read">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For sharded clusters, you can enable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-mongos-hedged-reads">
hedged reads
</a>
for non-primary
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference">
read preference
</a>
. To use hedged
reads, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
must have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.readHedgingMode">
<code class="leafygreen-ui-1l06pbn">
enabled support
</code>
</a>
for hedged reads (the default) and the
non-
<code class="leafygreen-ui-1l06pbn">
primary
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference">
read preferences
</a>
must
enable the use of hedged reads.
</p>
<p class="leafygreen-ui-1kp3ins">
To target secondaries on sharded clusters using hedged reads,
include both the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cursor-readpref-mode" target="_self">
<span>
mode
</span>
</a>
and the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cursor-readpref-hedge" target="_self">
<span>
hedgeOptions
</span>
</a>
, as in the following
examples:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Without a tag set
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find({ }).readPref(\n \"secondary\", // mode\n null, // tag set\n { enabled: true } // hedge options\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->{ <!-- -->}).<span class="lg-highlight-title lg-highlight-function">readPref</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondary"</span>, <span class="lg-highlight-comment">// mode</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-comment">// tag set</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">enabled</span>: <span class="lg-highlight-literal">true</span> } <span class="lg-highlight-comment">// hedge options</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
With a tag set
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find({ }).readPref(\n \"secondary\", // mode\n [ { \"datacenter\": \"B\" }, { } ], // tag set\n { enabled: true } // hedge options\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->{ <!-- -->}).<span class="lg-highlight-title lg-highlight-function">readPref</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondary"</span>, <span class="lg-highlight-comment">// mode</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"datacenter"</span>: <span class="lg-highlight-string">"B"</span> }<!-- -->, <!-- -->{ <!-- -->} ]<!-- -->, <span class="lg-highlight-comment">// tag set</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">enabled</span>: <span class="lg-highlight-literal">true</span> } <span class="lg-highlight-comment">// hedge options</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
</ul>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/data-modeling/design-patterns/group-data/bucket-pattern/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Group Data with the Bucket Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#group-data-with-the-bucket-pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="group-data-with-the-bucket-pattern">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#about-this-task" target="_self">
<span>
About this Task
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#steps" target="_self">
<span>
Steps
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#group-the-data-by-customerid" target="_self">
<span>
Group the data by customerId
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#add-an-identifier-and-count-for-each-bucket" target="_self">
<span>
Add an identifier and count for each bucket
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#next-steps" target="_self">
<span>
Next Steps
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#query-for-data-with-the-bucket-pattern" target="_self">
<span>
Query for Data with the Bucket Pattern
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#insert-data-with-the-bucket-pattern" target="_self">
<span>
Insert Data with the Bucket Pattern
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#results" target="_self">
<span>
Results
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The bucket pattern separates long series of data into distinct objects.
Separating large data series into smaller groups can improve query
access patterns and simplify application logic. Bucketing is useful when
you have similar objects that relate to a central entity, such as stock
trades made by a single user.
</p>
<p class="leafygreen-ui-1kp3ins">
You can use the bucket pattern for pagination by grouping your data
based on the elements that your application shows per page. This
approach uses MongoDB's flexible data model to store data according to
the data your applications needs.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
Time series collections
</a>
apply
the bucket pattern automatically, and are suitable for most
applications that involve bucketing time series data.
</p>
</div>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
About this Task
<a class="headerlink leafygreen-ui-1kepx47" href="#about-this-task" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="about-this-task">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider the following schema that tracks stock trades. The initial
schema does not use the bucket pattern, and stores each trade in an
individual document.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trades.insertMany(\n [\n {\n \"ticker\" : \"MDB\",\n \"customerId\": 123,\n \"type\" : \"buy\",\n \"quantity\" : 419,\n \"date\" : ISODate(\"2023-10-26T15:47:03.434Z\")\n },\n {\n \"ticker\" : \"MDB\",\n \"customerId\": 123,\n \"type\" : \"sell\",\n \"quantity\" : 29,\n \"date\" : ISODate(\"2023-10-30T09:32:57.765Z\")\n },\n {\n \"ticker\" : \"GOOG\",\n \"customerId\": 456,\n \"type\" : \"buy\",\n \"quantity\" : 50,\n \"date\" : ISODate(\"2023-10-31T11:16:02.120Z\")\n }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">trades</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span> <!-- -->: <span class="lg-highlight-string">"MDB"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customerId"</span>: <span class="lg-highlight-number">123</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"buy"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">419</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-26T15:47:03.434Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span> <!-- -->: <span class="lg-highlight-string">"MDB"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customerId"</span>: <span class="lg-highlight-number">123</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"sell"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">29</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-30T09:32:57.765Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span> <!-- -->: <span class="lg-highlight-string">"GOOG"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customerId"</span>: <span class="lg-highlight-number">456</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"buy"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">50</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-31T11:16:02.120Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The application shows stock trades made by a single customer at a time,
and shows 10 trades per page. To simplify the application logic, use the
bucket pattern to group the trades by
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
in groups of 10.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Steps
<a class="headerlink leafygreen-ui-1kepx47" href="#steps" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="steps">
</div>
</a>
</h2>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Reorganize the schema to have a single document for each\ncustomerId:With the bucket pattern:Documents with common customerId values are condensed into a\nsingle document, with the customerId being a top-level\nfield.Trades for that customer are grouped into an embedded array\nfield, called history.","name":"Group the data by customerId"},{"@type":"HowToStep","text":"The _id field value is a concatenation of the customerId\nand the first trade time in seconds (since the unix epoch)\nin the history field.The count field indicates how many elements are in that\ndocument's history array. The count field is used to\nimplement pagination logic.","name":"Add an identifier and count for each bucket"}],"name":"Steps","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Group the data by customerId
<a class="headerlink leafygreen-ui-1kepx47" href="#group-the-data-by-customerid" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="group-the-data-by-customerid">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Reorganize the schema to have a single document for each
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"customerId\": 123,\n \"history\": [\n {\n \"type\": \"buy\",\n \"ticker\": \"MDB\",\n \"qty\": 419,\n \"date\": ISODate(\"2023-10-26T15:47:03.434Z\")\n },\n {\n \"type\": \"sell\",\n \"ticker\": \"MDB\",\n \"qty\": 29,\n \"date\": ISODate(\"2023-10-30T09:32:57.765Z\")\n }\n ]\n},\n{\n \"customerId\": 456,\n \"history\": [\n {\n \"type\" : \"buy\",\n \"ticker\" : \"GOOG\",\n \"quantity\" : 50,\n \"date\" : ISODate(\"2023-10-31T11:16:02.120Z\")\n }\n ]\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customerId"</span>: <span class="lg-highlight-number">123</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"history"</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"buy"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span>: <span class="lg-highlight-string">"MDB"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"qty"</span>: <span class="lg-highlight-number">419</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-26T15:47:03.434Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"sell"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span>: <span class="lg-highlight-string">"MDB"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"qty"</span>: <span class="lg-highlight-number">29</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-30T09:32:57.765Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customerId"</span>: <span class="lg-highlight-number">456</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"history"</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"buy"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span> <!-- -->: <span class="lg-highlight-string">"GOOG"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">50</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-31T11:16:02.120Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
With the bucket pattern:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Documents with common
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
values are condensed into a
single document, with the
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
being a top-level
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Trades for that customer are grouped into an embedded array
field, called
<code class="leafygreen-ui-1l06pbn">
history
</code>
.
</p>
</li>
</ul>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Add an identifier and count for each bucket
<a class="headerlink leafygreen-ui-1kepx47" href="#add-an-identifier-and-count-for-each-bucket" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="add-an-identifier-and-count-for-each-bucket">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trades.drop()\n\ndb.trades.insertMany(\n [\n {\n \"_id\": \"123_1698349623\",\n \"customerId\": 123,\n \"count\": 2,\n \"history\": [\n {\n \"type\": \"buy\",\n \"ticker\": \"MDB\",\n \"qty\": 419,\n \"date\": ISODate(\"2023-10-26T15:47:03.434Z\")\n },\n {\n \"type\": \"sell\",\n \"ticker\": \"MDB\",\n \"qty\": 29,\n \"date\": ISODate(\"2023-10-30T09:32:57.765Z\")\n }\n ]\n },\n {\n \"_id\": \"456_1698765362\",\n \"customerId\": 456,\n \"count\": 1,\n \"history\": [\n {\n \"type\" : \"buy\",\n \"ticker\" : \"GOOG\",\n \"quantity\" : 50,\n \"date\" : ISODate(\"2023-10-31T11:16:02.120Z\")\n }\n ]\n },\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-ukaj9n">1</td><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">trades</span>.<span class="lg-highlight-title lg-highlight-function">drop</span>(<!-- -->)</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">2</td><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">3</td><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">trades</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">4</td><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">5</td><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-z611p6">6</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-string">"123_1698349623"</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">7</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customerId"</span>: <span class="lg-highlight-number">123</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-z611p6">8</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"count"</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">9</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"history"</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">10</td><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">11</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"buy"</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">12</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span>: <span class="lg-highlight-string">"MDB"</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">13</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"qty"</span>: <span class="lg-highlight-number">419</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">14</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-26T15:47:03.434Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">15</td><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">16</td><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">17</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"sell"</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">18</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span>: <span class="lg-highlight-string">"MDB"</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">19</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"qty"</span>: <span class="lg-highlight-number">29</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">20</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-30T09:32:57.765Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">21</td><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">22</td><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">23</td><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">24</td><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-z611p6">25</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-string">"456_1698765362"</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">26</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customerId"</span>: <span class="lg-highlight-number">456</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-z611p6">27</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"count"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">28</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"history"</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">29</td><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">30</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"buy"</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">31</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span> <!-- -->: <span class="lg-highlight-string">"GOOG"</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">32</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">50</span>,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">33</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-31T11:16:02.120Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">34</td><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">35</td><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">36</td><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">37</td><td class="leafygreen-ui-7razhx"> <!-- -->]</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">38</td><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field value is a concatenation of the
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
and the first trade time in seconds (since the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-unix-epoch">
unix epoch
</a>
)
in the
<code class="leafygreen-ui-1l06pbn">
history
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
count
</code>
field indicates how many elements are in that
document's
<code class="leafygreen-ui-1l06pbn">
history
</code>
array. The
<code class="leafygreen-ui-1l06pbn">
count
</code>
field is used to
implement pagination logic.
</p>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Next Steps
<a class="headerlink leafygreen-ui-1kepx47" href="#next-steps" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="next-steps">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
After you update your schema to use the bucket pattern, update your
application logic for reading and writing data. See the following
sections:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-bucket-pattern-next-steps-query" target="_self">
<span>
Query for Data with the Bucket Pattern
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-bucket-pattern-next-steps-insert" target="_self">
<span>
Insert Data with the Bucket Pattern
</span>
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-bucket-pattern-next-steps-query">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query for Data with the Bucket Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#query-for-data-with-the-bucket-pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="query-for-data-with-the-bucket-pattern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
In the updated schema, each document contains data for a single page in
the application. You can use the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
and
<code class="leafygreen-ui-1l06pbn">
count
</code>
field to
determine how to return and update data.
</p>
<p class="leafygreen-ui-1kp3ins">
To query for data on the appropriate page, use a regex query to return
data for a specified
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
, and use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.skip/#mongodb-method-cursor.skip">
<code class="leafygreen-ui-1l06pbn">
skip
</code>
</a>
to return to the data for the correct page. The regex
query on
<code class="leafygreen-ui-1l06pbn">
_id
</code>
uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/indexes/#std-label-index-type-id">
default _id index
</a>
,
which results in performant queries without the need for an additional
index.
</p>
<p class="leafygreen-ui-1kp3ins">
The following query returns data for the first page of trades for
customer
<code class="leafygreen-ui-1l06pbn">
123
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trades.find( { \"_id\": /^123_/ } ).sort( { _id: 1 } ).limit(1)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">trades</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-regexp">/^123_/</span> <!-- -->} ).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span> } ).<span class="lg-highlight-title lg-highlight-function">limit</span>(<span class="lg-highlight-number">1</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To return data for later pages, specify a
<code class="leafygreen-ui-1l06pbn">
skip
</code>
value of one less
than the page you want to show data for. For example, to show data for
page 10, run the following query:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trades.find( { \"_id\": /^123_/ } ).sort( { _id: 1 } ).skip(9).limit(1)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">trades</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-regexp">/^123_/</span> <!-- -->} ).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span> } ).<span class="lg-highlight-title lg-highlight-function">skip</span>(<span class="lg-highlight-number">9</span>).<span class="lg-highlight-title lg-highlight-function">limit</span>(<span class="lg-highlight-number">1</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The preceding query returns no results because the sample data only
contains documents for the first page.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-bucket-pattern-next-steps-insert">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Insert Data with the Bucket Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#insert-data-with-the-bucket-pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="insert-data-with-the-bucket-pattern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Now that the schema uses the bucket pattern, update your application
logic to insert new trades into the correct bucket. Use an update
command to insert the trade into the bucket with the appropriate
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
and bucket.
</p>
<p class="leafygreen-ui-1kp3ins">
The following command inserts a new trade for
<code class="leafygreen-ui-1l06pbn">
customerId: 123
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trades.updateOne( { \"_id\": /^123_/, \"count\": { $lt: 10 } },\n {\n \"$push\": {\n \"history\": {\n \"type\": \"buy\",\n \"ticker\": \"MSFT\",\n \"qty\": 42,\n \"date\": ISODate(\"2023-11-02T11:43:10\")\n }\n },\n \"$inc\": { \"count\": 1 },\n \"$setOnInsert\": { \"_id\": \"123_1698939791\", \"customerId\": 123 }\n },\n { upsert: true }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">trades</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>( <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-regexp">/^123_/</span>,<!-- --> <span class="lg-highlight-string">"count"</span>: <!-- -->{ <span class="lg-highlight-attr">$lt</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$push"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"history"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"buy"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ticker"</span>: <span class="lg-highlight-string">"MSFT"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"qty"</span>: <span class="lg-highlight-number">42</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-11-02T11:43:10"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$inc"</span>: <!-- -->{ <span class="lg-highlight-string">"count"</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$setOnInsert"</span>: <!-- -->{ <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-string">"123_1698939791"</span>, <span class="lg-highlight-string">"customerId"</span>: <span class="lg-highlight-number">123</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The application displays 10 trades per page. The update filter searches
for a document for
<code class="leafygreen-ui-1l06pbn">
customerId: 123
</code>
where the
<code class="leafygreen-ui-1l06pbn">
count
</code>
is less than
10, meaning that bucket does not contain a full page of data.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If there is a document that matches
<code class="leafygreen-ui-1l06pbn">
"_id": /^123_/
</code>
and its
<code class="leafygreen-ui-1l06pbn">
count
</code>
is less than 10, the update command pushes the new trade
into the matched document's
<code class="leafygreen-ui-1l06pbn">
history
</code>
array.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If there is
<strong>
not
</strong>
a matching document, the update command inserts a
new document with the new trade (because
<code class="leafygreen-ui-1l06pbn">
upsert
</code>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
). The
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field of the new document is a concatenation of the
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
and the time in seconds since the unix epoch of
the trade.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The logic for update commands avoids
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-unbounded-array">
unbounded arrays
</a>
by ensuring that no
<code class="leafygreen-ui-1l06pbn">
history
</code>
array contains more than 10
documents.
</p>
<p class="leafygreen-ui-1kp3ins">
After you run the update operation, the
<code class="leafygreen-ui-1l06pbn">
trades
</code>
collection has the
following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: '123_1698349623',\n customerId: 123,\n count: 3,\n history: [\n {\n type: 'buy',\n ticker: 'MDB',\n qty: 419,\n date: ISODate(\"2023-10-26T15:47:03.434Z\")\n },\n {\n type: 'sell',\n ticker: 'MDB',\n qty: 29,\n date: ISODate(\"2023-10-30T09:32:57.765Z\")\n },\n {\n type: 'buy',\n ticker: 'MSFT',\n qty: 42,\n date: ISODate(\"2023-11-02T11:43:10.000Z\")\n }\n ]\n },\n {\n _id: '456_1698765362',\n customerId: 456,\n count: 1,\n history: [\n {\n type: 'buy',\n ticker: 'GOOG',\n quantity: 50,\n date: ISODate(\"2023-10-31T11:16:02.120Z\")\n }\n ]\n }\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'123_1698349623'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">customerId</span>: <span class="lg-highlight-number">123</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">3</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">history</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'buy'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ticker</span>: <span class="lg-highlight-string">'MDB'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">419</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-26T15:47:03.434Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'sell'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ticker</span>: <span class="lg-highlight-string">'MDB'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">29</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-30T09:32:57.765Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'buy'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ticker</span>: <span class="lg-highlight-string">'MSFT'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">42</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-11-02T11:43:10.000Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'456_1698765362'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">customerId</span>: <span class="lg-highlight-number">456</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">history</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'buy'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ticker</span>: <span class="lg-highlight-string">'GOOG'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">50</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-10-31T11:16:02.120Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Results
<a class="headerlink leafygreen-ui-1kepx47" href="#results" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="results">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
After you implement the bucket pattern, you don't need to incorporate
pagination logic to return results in your application. The way the data
is stored matches the way it is used in the application.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
Time Series Collections
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-embedded-vs-linked-data">
Embedded Data Versus References
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/bucket/#mongodb-pipeline-pipe.-bucket">
<code class="leafygreen-ui-1l06pbn">
$bucket
</code>
</a>
aggregation stage
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://learn.mongodb.com/learning-paths/data-modeling-for-mongodb" target="_self">
<span>
MongoDB University Data Modeling Course
</span>
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/getLastError/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
getLastError
<a class="headerlink leafygreen-ui-1kepx47" href="#getlasterror" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="getlasterror">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
</ul>
</div>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
getLastError
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.getLastError" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.getLastError">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
Removed in MongoDB 5.1.
</p>
<p class="leafygreen-ui-1kp3ins">
Any code explicitly using
<code class="leafygreen-ui-1l06pbn">
getLastError
</code>
,
<code class="leafygreen-ui-1l06pbn">
db.getLastError()
</code>
, or
<code class="leafygreen-ui-1l06pbn">
db.getLastErrorObj()
</code>
should instead use the CRUD API to issue the
write with the desired
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
.
Information about the success or failure of the write operation will be
provided directly by the driver as a return value.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is not supported in MongoDB Atlas clusters.
For information on Atlas support for all commands,
see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/convert-command-line-options-to-yaml/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Convert Self-Managed Command-Line Options to YAML
<a class="headerlink leafygreen-ui-1kepx47" href="#convert-self-managed-command-line-options-to-yaml" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="convert-self-managed-command-line-options-to-yaml">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
accept
<code class="leafygreen-ui-1l06pbn">
--outputConfig
</code>
command-line option to output the configuration used by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance.
</p>
<p class="leafygreen-ui-1kp3ins">
You can use this option to convert command-line options to YAML
configuration.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Convert
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
Command-Line Options to YAML
<a class="headerlink leafygreen-ui-1kepx47" href="#convert-mongod-command-line-options-to-yaml" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="convert-mongod-command-line-options-to-yaml">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Consider the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
invocation that uses the
command-line options:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --shardsvr --replSet myShard --dbpath /var/lib/mongodb --bind_ip localhost,My-Example-Hostname --fork --logpath /var/log/mongodb/mongod.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file","programmingLanguage":"Bash"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --shardsvr --replSet myShard --dbpath <!-- -->/var/lib/mongodb<!-- --> --bind_ip localhost,My-Example-Hostname --fork --logpath <!-- -->/var/log/mongodb/mongod.log<!-- --> --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile <!-- -->/path/to/my<!-- -->/CA<!-- -->/file<!-- --> --tlsCertificateKeyFile <!-- -->/path/to/my/certificate/file<!-- --> --tlsClusterFile <!-- -->/path/to/my/cluster/membership/file</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--outputConfig">
<code class="leafygreen-ui-1l06pbn">
--outputConfig
</code>
</a>
command-line option to generate the corresponding YAML file.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --shardsvr --replSet myShard --dbpath /var/lib/mongodb --bind_ip localhost,My-Example-Hostname --fork --logpath /var/log/mongodb/mongod.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file --outputConfig","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --shardsvr --replSet myShard --dbpath <!-- -->/var/lib/mongodb<!-- --> --bind_ip localhost,My-Example-Hostname --fork --logpath <!-- -->/var/log/mongodb/mongod.log<!-- --> --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile <!-- -->/path/to/my<!-- -->/CA<!-- -->/file<!-- --> --tlsCertificateKeyFile <!-- -->/path/to/my/certificate/file<!-- --> --tlsClusterFile <!-- -->/path/to/my/cluster/membership/file<!-- --> --outputConfig</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
outputs the following YAML to
<code class="leafygreen-ui-1l06pbn">
stdout
</code>
and
exits:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"net:\n bindIp: localhost,My-Example-Hostname\n tls:\n CAFile: /path/to/my/CA/file\n certificateKeyFile: /path/to/my/certificate/file\n clusterFile: /path/to/my/cluster/membership/file\n mode: requireTLS\noutputConfig: true\nprocessManagement:\n fork: true\nreplication:\n replSet: myShard\nsecurity:\n clusterAuthMode: x509\nsharding:\n clusterRole: shardsvr\nstorage:\n dbPath: /var/lib/mongodb\nsystemLog:\n destination: file\n path: /var/log/mongodb/mongod.log","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-string">localhost,My-Example-Hostname</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tls:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">CAFile:</span> <span class="lg-highlight-string">/path/to/my/CA/file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFile:</span> <span class="lg-highlight-string">/path/to/my/certificate/file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterFile:</span> <span class="lg-highlight-string">/path/to/my/cluster/membership/file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string">requireTLS</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">outputConfig:</span> <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">processManagement:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fork:</span> <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">replSet:</span> <span class="lg-highlight-string">myShard</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">security:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterAuthMode:</span> <span class="lg-highlight-string">x509</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">sharding:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterRole:</span> <span class="lg-highlight-string">shardsvr</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbPath:</span> <span class="lg-highlight-string">/var/lib/mongodb</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string">file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string">/var/log/mongodb/mongod.log</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To create a configuration file, copy the generated content into a
file and delete the
<code class="leafygreen-ui-1l06pbn">
outputConfig
</code>
setting from the YAML.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Convert
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
Command-Line Options to YAML
<a class="headerlink leafygreen-ui-1kepx47" href="#convert-mongos-command-line-options-to-yaml" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="convert-mongos-command-line-options-to-yaml">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Consider the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
invocation that uses the
command-line options:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongos --configdb myCSRS/cfg1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,My-Example-MONGOS-Hostname --fork --logpath /var/log/mongodb/mongos.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file","programmingLanguage":"Bash"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongos --configdb myCSRS<!-- -->/cfg<!-- -->1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,My-Example-MONGOS-Hostname --fork --logpath <!-- -->/var/log/mongodb/mongos.log<!-- --> --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile <!-- -->/path/to/my<!-- -->/CA<!-- -->/file<!-- --> --tlsCertificateKeyFile <!-- -->/path/to/my/certificate/file<!-- --> --tlsClusterFile <!-- -->/path/to/my/cluster/membership/file</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-option-mongos.--outputConfig">
<code class="leafygreen-ui-1l06pbn">
--outputConfig
</code>
</a>
command-line option to generate the corresponding YAML for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongos --configdb myCSRS/cfg1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,My-Example-MONGOS-Hostname --fork --logpath /var/log/mongodb/mongos.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file --outputConfig","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongos --configdb myCSRS<!-- -->/cfg<!-- -->1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,My-Example-MONGOS-Hostname --fork --logpath <!-- -->/var/log/mongodb/mongos.log<!-- --> --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile <!-- -->/path/to/my<!-- -->/CA<!-- -->/file<!-- --> --tlsCertificateKeyFile <!-- -->/path/to/my/certificate/file<!-- --> --tlsClusterFile <!-- -->/path/to/my/cluster/membership/file<!-- --> --outputConfig</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
outputs the following YAML to
<code class="leafygreen-ui-1l06pbn">
stdout
</code>
and exits:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"net:\n bindIp: localhost,My-Example-MONGOS-Hostname\n tls:\n CAFile: /path/to/my/CA/file\n certificateKeyFile: /path/to/my/certificate/file\n clusterFile: /path/to/my/cluster/membership/file\n mode: requireTLS\noutputConfig: true\nprocessManagement:\n fork: true\nsecurity:\n clusterAuthMode: x509\nsharding:\n configDB: myCSRS/cfg1.example.net:27019,cfg2.example.net:27019\nsystemLog:\n destination: file\n path: /var/log/mongodb/mongos.log","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-string">localhost,My-Example-MONGOS-Hostname</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tls:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">CAFile:</span> <span class="lg-highlight-string">/path/to/my/CA/file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFile:</span> <span class="lg-highlight-string">/path/to/my/certificate/file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterFile:</span> <span class="lg-highlight-string">/path/to/my/cluster/membership/file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string">requireTLS</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">outputConfig:</span> <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">processManagement:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fork:</span> <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">security:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterAuthMode:</span> <span class="lg-highlight-string">x509</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">sharding:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">configDB:</span> <span class="lg-highlight-string">myCSRS/cfg1.example.net:27019,cfg2.example.net:27019</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string">file</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string">/var/log/mongodb/mongos.log</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To create a configuration file, copy the generated content into a
file and delete the
<code class="leafygreen-ui-1l06pbn">
outputConfig
</code>
setting from the YAML.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$arrayToObject (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-arraytoobject--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-arraytoobject--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-arrayToObject" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-arrayToObject">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Converts an array into a single document; the array must be
either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
An array of two-element arrays where the first element is the
field name, and the second element is the field value:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ [ [ \"item\", \"abc123\" ], [ \"qty\", 25 ] ] ]"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[ [ [ "item", "abc123" ], [ "qty", 25 ] ] ]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
- OR -
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
An array of documents that contains two fields,
<code class="leafygreen-ui-1l06pbn">
k
</code>
and
<code class="leafygreen-ui-1l06pbn">
v
</code>
where:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
k
</code>
field contains the field name.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
v
</code>
field contains the value of the field.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ [ { \"k\": \"item\", \"v\": \"abc123\" }, { \"k\": \"qty\", \"v\": 25 } ] ]"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[ [ { "k": "item", "v": "abc123" }, { "k": "qty", "v": 25 } ] ]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-arrayToObject" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $arrayToObject: <expression> }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$arrayToObject</span>: <<!-- -->expression<!-- -->> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
<expression>
</code>
can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to an array of two-element
arrays or array of documents that contains "k" and "v" fields.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If the name of a field repeats in the array,
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Starting in 4.0.5,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-arrayToObject" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</span>
</a>
uses the last value
for that field. For 4.0.0-4.0.4, the value used depends on the driver.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Starting in 3.6.10,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-arrayToObject" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</span>
</a>
uses the last value
for that field. For 3.6.0-3.6.9, the value used depends on the driver.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Starting in 3.4.19,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-arrayToObject" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</span>
</a>
uses the last value
for that field. For 3.4.0-3.4.19, the value uses depends on the
driver.
</p>
</li>
</ul>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:60%"/>
<col style="width:40%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Results
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $arrayToObject: [\n [ { \"k\": \"item\", \"v\": \"abc123\" },\n { \"k\": \"qty\", \"v\": \"$qty\" } ]\n] }","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span> $arrayToObject<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">[</span> <span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"k"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"item"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"v"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"abc123"</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"k"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"qty"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"v"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"$qty"</span> <span class="lg-highlight-punctuation">}</span> <span class="lg-highlight-punctuation">]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span> <span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Given a document with the field
<code class="leafygreen-ui-1l06pbn">
qty
</code>
and value
<code class="leafygreen-ui-1l06pbn">
25
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-arrayToObject" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</span>
</a>
returns:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"item\" : \"abc123\", \"qty\" : 25 }","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"item"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"abc123"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"qty"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">25</span> <span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $arrayToObject: { $literal: [\n [ \"item\", \"abc123\" ], [ \"qty\", 25 ]\n] } }","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span> $arrayToObject<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> $literal<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">[</span> <span class="lg-highlight-string">"item"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-string">"abc123"</span> <span class="lg-highlight-punctuation">]</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-punctuation">[</span> <span class="lg-highlight-string">"qty"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-number">25</span> <span class="lg-highlight-punctuation">]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span> <span class="lg-highlight-punctuation">}</span> <span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"item\" : \"abc123\", \"qty\" : 25 }","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"item"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"abc123"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"qty"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">25</span> <span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $arrayToObject: { $literal: [\n { \"k\": \"item\", \"v\": \"123abc\" },\n { \"k\": \"item\", \"v\": \"abc123\" }\n] } }","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span> $arrayToObject<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> $literal<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"k"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"item"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"v"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"123abc"</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"k"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"item"</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"v"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"abc123"</span> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span> <span class="lg-highlight-punctuation">}</span> <span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"item\" : \"abc123\" }","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"item"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"abc123"</span> <span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Starting in versions 4.0.5+ (3.6.10+ and 3.4.19+), if the name
of a field repeats in the array,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-arrayToObject" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</span>
</a>
uses the last value for that field.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#-arraytoobject--example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-arraytoobject--example">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Consider a
<code class="leafygreen-ui-1l06pbn">
inventory
</code>
collection with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"ABC1\", dimensions: [ { \"k\": \"l\", \"v\": 25} , { \"k\": \"w\", \"v\": 10 }, { \"k\": \"uom\", \"v\": \"cm\" } ] }\n{ \"_id\" : 2, \"item\" : \"ABC2\", dimensions: [ [ \"l\", 50 ], [ \"w\", 25 ], [ \"uom\", \"cm\" ] ] }\n{ \"_id\" : 3, \"item\" : \"ABC3\", dimensions: [ [ \"l\", 25 ], [ \"l\", \"cm\" ], [ \"l\", 50 ] ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC1"</span>, <span class="lg-highlight-attr">dimensions</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"k"</span>: <span class="lg-highlight-string">"l"</span>, <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-number">25</span>} <!-- -->, <!-- -->{ <span class="lg-highlight-string">"k"</span>: <span class="lg-highlight-string">"w"</span>, <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-number">10</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"k"</span>: <span class="lg-highlight-string">"uom"</span>, <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-string">"cm"</span> } ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC2"</span>, <span class="lg-highlight-attr">dimensions</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"l"</span>, <span class="lg-highlight-number">50</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"w"</span>, <span class="lg-highlight-number">25</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"uom"</span>, <span class="lg-highlight-string">"cm"</span> ] ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC3"</span>, <span class="lg-highlight-attr">dimensions</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"l"</span>, <span class="lg-highlight-number">25</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"l"</span>, <span class="lg-highlight-string">"cm"</span> ]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"l"</span>, <span class="lg-highlight-number">50</span> ] ] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation pipeline operation use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-arrayToObject" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</span>
</a>
to return the
<code class="leafygreen-ui-1l06pbn">
dimensions
</code>
field as a
document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.aggregate(\n [\n {\n $project: {\n item: 1,\n dimensions: { $arrayToObject: \"$dimensions\" }\n }\n }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dimensions</span>: <!-- -->{ <span class="lg-highlight-attr">$arrayToObject</span>: <span class="lg-highlight-string">"$dimensions"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"ABC1\", \"dimensions\" : { \"l\" : 25, \"w\" : 10, \"uom\" : \"cm\" } }\n{ \"_id\" : 2, \"item\" : \"ABC2\", \"dimensions\" : { \"l\" : 50, \"w\" : 25, \"uom\" : \"cm\" } }\n{ \"_id\" : 3, \"item\" : \"ABC3\", \"dimensions\" : { \"l\" : 50 } }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC1"</span>, <span class="lg-highlight-string">"dimensions"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"l"</span> <!-- -->: <span class="lg-highlight-number">25</span>, <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"uom"</span> <!-- -->: <span class="lg-highlight-string">"cm"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC2"</span>, <span class="lg-highlight-string">"dimensions"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"l"</span> <!-- -->: <span class="lg-highlight-number">50</span>, <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-number">25</span>, <span class="lg-highlight-string">"uom"</span> <!-- -->: <span class="lg-highlight-string">"cm"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC3"</span>, <span class="lg-highlight-string">"dimensions"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"l"</span> <!-- -->: <span class="lg-highlight-number">50</span> } }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Starting in versions 4.0.5+ (3.6.10+ and 3.4.19+), if the name of a
field repeats in the array,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-arrayToObject" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</span>
</a>
uses the last
value for that field.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$objectToArray
</code>
+
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#-objecttoarray----arraytoobject-example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-objecttoarray----arraytoobject-example">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Consider a
<code class="leafygreen-ui-1l06pbn">
inventory
</code>
collection with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"ABC1\", instock: { warehouse1: 2500, warehouse2: 500 } }\n{ \"_id\" : 2, \"item\" : \"ABC2\", instock: { warehouse2: 500, warehouse3: 200} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC1"</span>, <span class="lg-highlight-attr">instock</span>: <!-- -->{ <span class="lg-highlight-attr">warehouse1</span>: <span class="lg-highlight-number">2500</span>, <span class="lg-highlight-attr">warehouse2</span>: <span class="lg-highlight-number">500</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC2"</span>, <span class="lg-highlight-attr">instock</span>: <!-- -->{ <span class="lg-highlight-attr">warehouse2</span>: <span class="lg-highlight-number">500</span>, <span class="lg-highlight-attr">warehouse3</span>: <span class="lg-highlight-number">200</span>} }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation pipeline operation calculates the total in
stock for each item and adds to the
<code class="leafygreen-ui-1l06pbn">
instock
</code>
document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.aggregate( [\n { $addFields: { instock: { $objectToArray: \"$instock\" } } },\n { $addFields: { instock: { $concatArrays: [ \"$instock\", [ { \"k\": \"total\", \"v\": { $sum: \"$instock.v\" } } ] ] } } } ,\n { $addFields: { instock: { $arrayToObject: \"$instock\" } } }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$addFields</span>: <!-- -->{ <span class="lg-highlight-attr">instock</span>: <!-- -->{ <span class="lg-highlight-attr">$objectToArray</span>: <span class="lg-highlight-string">"$instock"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$addFields</span>: <!-- -->{ <span class="lg-highlight-attr">instock</span>: <!-- -->{ <span class="lg-highlight-attr">$concatArrays</span>: <!-- -->[ <span class="lg-highlight-string">"$instock"</span>, <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"k"</span>: <span class="lg-highlight-string">"total"</span>, <span class="lg-highlight-string">"v"</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$instock.v"</span> } } ] ] } } } <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$addFields</span>: <!-- -->{ <span class="lg-highlight-attr">instock</span>: <!-- -->{ <span class="lg-highlight-attr">$arrayToObject</span>: <span class="lg-highlight-string">"$instock"</span> } } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"ABC1\", \"instock\" : { \"warehouse1\" : 2500, \"warehouse2\" : 500, \"total\" : 3000 } }\n{ \"_id\" : 2, \"item\" : \"ABC2\", \"instock\" : { \"warehouse2\" : 500, \"warehouse3\" : 200, \"total\" : 700 } }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC1"</span>, <span class="lg-highlight-string">"instock"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"warehouse1"</span> <!-- -->: <span class="lg-highlight-number">2500</span>, <span class="lg-highlight-string">"warehouse2"</span> <!-- -->: <span class="lg-highlight-number">500</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">3000</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC2"</span>, <span class="lg-highlight-string">"instock"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"warehouse2"</span> <!-- -->: <span class="lg-highlight-number">500</span>, <span class="lg-highlight-string">"warehouse3"</span> <!-- -->: <span class="lg-highlight-number">200</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">700</span> } }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/objectToArray/#mongodb-expression-exp.-objectToArray">
<code class="leafygreen-ui-1l06pbn">
$objectToArray
</code>
</a>
</p>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/cursor.tryNext/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
cursor.tryNext()
<a class="headerlink leafygreen-ui-1kepx47" href="#cursor.trynext--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="cursor.trynext--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
</ul>
</div>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
cursor.tryNext()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.tryNext" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-cursor.tryNext">
</div>
</a>
</dt>
<dd>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for a language-specific driver, such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<table class="css-11h39yh e1nex8bq0">
<colgroup>
<col class="field-name"/>
<col class="field-body"/>
</colgroup>
<tbody>
<tr class="css-x8snli">
<th>
Returns
<!-- -->
:
</th>
<td>
The next document in the cursor returned by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
db.collection.find()
</code>
</a>
method or
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</td>
</tr>
</tbody>
</table>
</dd>
</dl>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
cursor.tryNext()
</code>
is a special case of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.next/#mongodb-method-cursor.next">
<code class="leafygreen-ui-1l06pbn">
cursor.next()
</code>
</a>
method that returns the next element in the iteration if available or
else
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/change-events/createIndexes/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
createIndexes Event
<a class="headerlink leafygreen-ui-1kepx47" href="#createindexes-event" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="createindexes-event">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#summary" target="_self">
<span>
Summary
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#description" target="_self">
<span>
Description
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Summary
<a class="headerlink leafygreen-ui-1kepx47" href="#summary" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="summary">
</div>
</a>
</h2>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-createIndexes" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-data-createIndexes">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
6.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
A
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
event occurs when an index is created on the collection
and the change stream has the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/change-events/#std-label-change-streams-expanded-events">
showExpandedEvents
</a>
option set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Description
<a class="headerlink leafygreen-ui-1kepx47" href="#description" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="description">
</div>
</a>
</h2>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:60%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
_id
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--id">
</span>
<p class="leafygreen-ui-1kp3ins">
A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-BSON">
BSON
</a>
object which serves as an identifier for the
change stream event. This value is used as the
<code class="leafygreen-ui-1l06pbn">
resumeToken
</code>
for the
<code class="leafygreen-ui-1l06pbn">
resumeAfter
</code>
parameter when resuming a change stream.
The
<code class="leafygreen-ui-1l06pbn">
_id
</code>
object has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_data\" : <bindata|hex>\n}"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "_data" : <BinData|hex string></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
_data
</code>
type depends on the MongoDB versions
and, in some cases, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
feature compatibility version (fCV)
</a>
at the time of the change stream's
opening or resumption. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-change-stream-resume-token">
Resume Tokens
</a>
for the
full list of
<code class="leafygreen-ui-1l06pbn">
_data
</code>
types.
</p>
<p class="leafygreen-ui-1kp3ins">
For an example of resuming a change stream by
<code class="leafygreen-ui-1l06pbn">
resumeToken
</code>
, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-change-stream-resume">
Resume a Change Stream
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
clusterTime
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Timestamp
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--clusterTime">
</span>
<p class="leafygreen-ui-1kp3ins">
The timestamp from the oplog entry associated with the event.
</p>
<p class="leafygreen-ui-1kp3ins">
Change stream event notifications associated with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
multi-document transaction
</a>
all have the same
<code class="leafygreen-ui-1l06pbn">
clusterTime
</code>
value: the time when the transaction
was committed.
</p>
<p class="leafygreen-ui-1kp3ins">
Events with the same
<code class="leafygreen-ui-1l06pbn">
clusterTime
</code>
may not all relate to the same transaction.
Some events don't relate to a transaction at all. Starting in MongoDB 8.0,
this may be true for events on any deployment. In previous versions, this
behavior was possible only for events on a sharded cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
To identify events for a single transaction, you can use the
combination of
<code class="leafygreen-ui-1l06pbn">
lsid
</code>
and
<code class="leafygreen-ui-1l06pbn">
txnNumber
</code>
in the change stream
event document.
</p>
<div>
<p>
<em>
Changed
<!-- -->
in version
<!-- -->
8.0
</em>
.
</p>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
collectionUUID
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
UUID
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--collectionUUID">
</span>
<p class="leafygreen-ui-1kp3ins">
<span class="leafygreen-ui-vm4wms" tabindex="0">
UUID
</span>
identifying the collection
where the change occurred.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
6.0
</em>
.
</p>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
lsid
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--lsid">
</span>
<p class="leafygreen-ui-1kp3ins">
The identifier for the session associated with the transaction.
</p>
<p class="leafygreen-ui-1kp3ins">
Only present if the operation is part of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
multi-document
transaction
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ns
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--ns">
</span>
<p class="leafygreen-ui-1kp3ins">
The namespace (database and or collection) affected by the event.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ns.db
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--ns.db">
</span>
<p class="leafygreen-ui-1kp3ins">
The name of the database where the event occurred.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ns.coll
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--ns.coll">
</span>
<p class="leafygreen-ui-1kp3ins">
The name of the collection where the event occurred.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
operationDescription
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--operationDescription">
</span>
<p class="leafygreen-ui-1kp3ins">
Additional information on the change operation.
</p>
<p class="leafygreen-ui-1kp3ins">
This document and its subfields only appears when the change stream uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/change-events/#std-label-change-streams-expanded-events">
expanded events
<!-- -->
.
</a>
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
6.0
</em>
.
</p>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
operationDescription.
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
indexes
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
array
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
An array of documents listing the indexes that were created
by the operation.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
6.0
</em>
.
</p>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
operationType
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--operationType">
</span>
<p class="leafygreen-ui-1kp3ins">
The type of operation that the change notification reports.
</p>
<p class="leafygreen-ui-1kp3ins">
Returns a value of
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
for these change events.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
txnNumber
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
NumberLong
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--txnNumber">
</span>
<p class="leafygreen-ui-1kp3ins">
Together with the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label--idref--lsid" target="_self">
<span>
lsid
</span>
</a>
, a number that helps uniquely
identify a transction.
</p>
<p class="leafygreen-ui-1kp3ins">
Only present if the operation is part of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
multi-document
transaction
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
wallTime
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ISODate">
ISODate
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label--idref--wallTime">
</span>
<p class="leafygreen-ui-1kp3ins">
The server date and time of the database operation.
<code class="leafygreen-ui-1l06pbn">
wallTime
</code>
differs from
<code class="leafygreen-ui-1l06pbn">
clusterTime
</code>
in that
<code class="leafygreen-ui-1l06pbn">
clusterTime
</code>
is a timestamp
taken from the oplog entry associated with the database operation
event.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
6.0
</em>
.
</p>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following example shows a
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
event:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": { <resumetoken> },\n \"operationType\": \"createIndexes\",\n \"clusterTime\": Timestamp({ t: 1651257835, i: 1 }),\n \"collectionUUID\": UUID(\"06bced37-7cc8-4267-96aa-a58a422153d8\"),\n \"wallTime\": ISODate(\"2022-04-29T18:43:55.160Z\"),\n \"ns\": {\n \"db\": \"test\",\n \"coll\": \"authors\"\n },\n \"operationDescription\": {\n \"indexes\": [\n { \"v\": 2, \"key\": { \"name\": 1 }, \"name\": \"name_1\" }\n ]\n }\n}","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"_id"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> <ResumeToken> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"operationType"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"createIndexes"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"clusterTime"</span><span class="lg-highlight-punctuation">:</span> Timestamp(<span class="lg-highlight-punctuation">{</span> t<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1651257835</span><span class="lg-highlight-punctuation">,</span> i<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span> <span class="lg-highlight-punctuation">}</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"collectionUUID"</span><span class="lg-highlight-punctuation">:</span> UUID(<span class="lg-highlight-string">"06bced37-7cc8-4267-96aa-a58a422153d8"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"wallTime"</span><span class="lg-highlight-punctuation">:</span> ISODate(<span class="lg-highlight-string">"2022-04-29T18:43:55.160Z"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ns"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"db"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"test"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"coll"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"authors"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"operationDescription"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"indexes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"v"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">2</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"key"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> <span class="lg-highlight-attr">"name"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span> <span class="lg-highlight-attr">"name"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"name_1"</span> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/administration/deploy-manage-self-managed-replica-sets/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Deploy and Manage Self-Managed Replica Sets
<a class="headerlink leafygreen-ui-1kepx47" href="#deploy-and-manage-self-managed-replica-sets" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="deploy-and-manage-self-managed-replica-sets">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
These documents provide instructions on how to deploy and manage
self-managed MongoDB replica sets.
</p>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/replica-set-deployment/#std-label-server-replica-set-deploy-all">
Deployment Tutorials
</a>
</dt>
<dd class="css-1ufxuu7">
Learn how to deploy a self-managed replica set.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/replica-set-member-configuration/#std-label-member-config-tutorials">
Configuration Tutorials
</a>
</dt>
<dd class="css-1ufxuu7">
Learn how to configure a self-managed replica set.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/replica-set-maintenance/#std-label-replica-set-maintenance-tutorials">
Maintenance Tutorials
</a>
</dt>
<dd class="css-1ufxuu7">
Learn how to maintain a self-managed replica set.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replication/#std-label-replication-toc">
Reference
</a>
</dt>
<dd class="css-1ufxuu7">
Reference documentation for self-managed replica sets.
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/core/map-reduce-concurrency/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Map-Reduce Concurrency
<a class="headerlink leafygreen-ui-1kepx47" href="#map-reduce-concurrency" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="map-reduce-concurrency">
</div>
</a>
</h1>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Aggregation Pipeline as an Alternative to Map-Reduce
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce">
map-reduce
</a>
is
deprecated:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Instead of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce">
map-reduce
</a>
, you should use an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation pipeline
</a>
. Aggregation
pipelines provide better performance and usability than map-reduce.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can rewrite map-reduce operations using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference">
aggregation pipeline
stages
</a>
, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
, and others.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For map-reduce operations that require custom functionality, you can
use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
aggregation
operators. You can use those
operators to define custom aggregation expressions in JavaScript.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For examples of aggregation pipeline alternatives to map-reduce, see:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/map-reduce-to-aggregation-pipeline/">
Map-Reduce to Aggregation Pipeline
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/map-reduce-examples/">
Map-Reduce Examples
</a>
</p>
</li>
</ul>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The map-reduce operation is composed of many tasks, including reads
from the input collection, executions of the
<code class="leafygreen-ui-1l06pbn">
map
</code>
function,
executions of the
<code class="leafygreen-ui-1l06pbn">
reduce
</code>
function, writes to a temporary collection
during processing, and writes to the output collection.
</p>
<p class="leafygreen-ui-1kp3ins">
During the operation, map-reduce takes the following locks:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The read phase takes a read lock. It yields every 100 documents.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The insert into the temporary collection takes a write lock for a
single write.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the output collection does not exist, the creation of the output
collection takes a write lock.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the output collection exists, then the output actions (i.e.
<code class="leafygreen-ui-1l06pbn">
merge
</code>
,
<code class="leafygreen-ui-1l06pbn">
replace
</code>
,
<code class="leafygreen-ui-1l06pbn">
reduce
</code>
) take a write lock. This write
lock is
<em>
global
</em>
, and blocks all operations on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance.
</p>
</li>
</ul>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/unsetSharding/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
unsetSharding
<a class="headerlink leafygreen-ui-1kepx47" href="#unsetsharding" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="unsetsharding">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
</ul>
</div>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
unsetSharding
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.unsetSharding" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.unsetSharding">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Removed in MongoDB 5.0.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.unsetSharding" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
unsetSharding
</code>
</span>
</a>
is an internal command that supports
sharding functionality.
</p>
</dd>
</dl>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is supported in all MongoDB Atlas clusters.
For information on Atlas support for all commands, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/createIndexes/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
createIndexes
<a class="headerlink leafygreen-ui-1kepx47" href="#createindexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="createindexes">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#command-fields" target="_self">
<span>
Command Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self">
<span>
Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#index-names" target="_self">
<span>
Index Names
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#replica-sets-and-sharded-clusters" target="_self">
<span>
Replica Sets and Sharded Clusters
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#collation-and-index-types" target="_self">
<span>
Collation and Index Types
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#stable-api" target="_self">
<span>
Stable API
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#concurrency" target="_self">
<span>
Concurrency
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#memory-usage-limit" target="_self">
<span>
Memory Usage Limit
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#index-options" target="_self">
<span>
Index Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#wildcard-indexes" target="_self">
<span>
Wildcard Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#transactions" target="_self">
<span>
Transactions
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#commit-quorum-contrasted-with-write-concern" target="_self">
<span>
Commit Quorum Contrasted with Write Concern
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-a-wildcard-index" target="_self">
<span>
Create a Wildcard Index
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-index-with-commit-quorum" target="_self">
<span>
Create Index With Commit Quorum
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output" target="_self">
<span>
Output
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.createIndexes" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.createIndexes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Builds one or more indexes on a collection.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
In
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
, this command can also be run through the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndex()
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndexes/#mongodb-method-db.collection.createIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndexes()
</code>
</a>
helper methods.
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
Helper methods are convenient for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
users, but they may not
return the same level of information as database commands. In cases where
the convenience is not needed or the additional return fields are required,
use the database command.
</p>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is supported in all MongoDB Atlas clusters.
For information on Atlas support for all commands, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
command takes the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n createIndexes: <collection>,\n indexes: [\n {\n key: {\n <key-value_pair>,\n <key-value_pair>,\n ...\n },\n name: <index_name>,\n <option1>,\n <option2>,\n ...\n },\n { ... },\n { ... }\n ],\n writeConcern: { <write> },\n commitQuorum: <int|string>,\n comment: <any>\n }\n )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">createIndexes</span>: <<!-- -->collection<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">indexes</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <<!-- -->key<!-- -->-<!-- -->value_pair<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- --><<!-- -->key<!-- -->-<!-- -->value_pair<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <<!-- -->index_name<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- --><<!-- -->option1<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- --><<!-- -->option2<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->...<!-- --> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->...<!-- --> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: <!-- -->{ <!-- --><write concern> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> commitQuorum: <int|string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> comment: <any></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
command takes the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The collection for which to create indexes.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
indexes
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
array
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Specifies the indexes to create. Each document in the array specifies a
separate index.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
writeConcern
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. A document expressing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/">
write concern
</a>
. Omit to use the default write concern.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
commitQuorum
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer or string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-cmd-commitQuorum">
</span>
<p class="leafygreen-ui-1kp3ins">
Optional. The minimum number of data-bearing replica
set members (i.e. commit quorum), including the primary, that
must report a successful
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations-replicated-build">
index build
</a>
before the primary
marks the
<code class="leafygreen-ui-1l06pbn">
indexes
</code>
as ready.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB v5.0, you can resume some
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations-build-failure">
interrupted index builds
</a>
when the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setIndexCommitQuorum/#mongodb-dbcommand-dbcmd.setIndexCommitQuorum">
<code class="leafygreen-ui-1l06pbn">
commit quorum is set
</code>
</a>
to
<code class="leafygreen-ui-1l06pbn">
"votingMembers"
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Replica set nodes in a commit quorum must have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.buildIndexes">
<code class="leafygreen-ui-1l06pbn">
members[n].buildIndexes
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
. If any voting nodes have
<code class="leafygreen-ui-1l06pbn">
members[n].buildIndexes
</code>
set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
, you can't use the
default
<code class="leafygreen-ui-1l06pbn">
"votingMembers"
</code>
commit quorum. Either configure all
nodes with
<code class="leafygreen-ui-1l06pbn">
members[n].buildIndexes
</code>
set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, or
select a different commit quorum.
</p>
<p class="leafygreen-ui-1kp3ins">
Supports the following values:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
"votingMembers"
</code>
- all data-bearing voting replica set
members (
<em>
Default
</em>
). A "voting" member is any replica set member
where
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes">
<code class="leafygreen-ui-1l06pbn">
members[n].votes
</code>
</a>
is greater than
<code class="leafygreen-ui-1l06pbn">
0
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
- a simple majority of data-bearing replica set members.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
<int>
</code>
- a specific number of data-bearing replica set members.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
- Disables quorum-voting behavior. Members
start the index build simultaneously but do
<em>
not
</em>
vote or wait for quorum before completing the
index build. If you start an index build with
a commit quorum of
<code class="leafygreen-ui-1l06pbn">
0
</code>
, you cannot later modify the
commit quorum using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setIndexCommitQuorum/#mongodb-dbcommand-dbcmd.setIndexCommitQuorum">
<code class="leafygreen-ui-1l06pbn">
setIndexCommitQuorum
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-replica-set-tag-sets/">
tag name
<!-- -->
.
</a>
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
comment
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
any
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. A user-provided comment to attach to this command. Once set, this
comment appears alongside records of this command in the following
locations:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
mongod log messages
</a>
, in the
<code class="leafygreen-ui-1l06pbn">
attr.command.cursor.comment
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler">
Database profiler
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp">
<code class="leafygreen-ui-1l06pbn">
currentOp
</code>
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
A comment can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON type
</a>
(string, integer, object, array, etc).
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-options">
</span>
<p class="leafygreen-ui-1kp3ins">
Each document in the
<code class="leafygreen-ui-1l06pbn">
indexes
</code>
array can take the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
key
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies the index's fields. For each field, specify a
key-value pair in which the key is the name of the field to
index and the value is either the index direction or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/#std-label-index-types">
index
type
</a>
. If specifying direction, specify
<code class="leafygreen-ui-1l06pbn">
1
</code>
for
ascending or
<code class="leafygreen-ui-1l06pbn">
-1
</code>
for descending.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports several different index types, including:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-feature-text">
text
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/geospatial-queries/#std-label-index-feature-geospatial">
geospatial
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-type-hashed">
hashed indexes
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/#std-label-index-types">
index types
</a>
for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/#std-label-wildcard-index-core">
Wildcard indexes
</a>
support workloads where
users query against custom fields or a large variety of fields in a
collection:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can create a wildcard index on a specific field and its
subpaths or on all of the fields in a document.
</p>
<p class="leafygreen-ui-1kp3ins">
For details see,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/#std-label-wildcard-index-core">
Wildcard Indexes
<!-- -->
.
</a>
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
name
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A name that uniquely identifies the index.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
unique
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Creates a unique index so that the collection will not accept
insertion or update of documents where the index key value matches an existing
value in the index.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify
<code class="leafygreen-ui-1l06pbn">
true
</code>
to create a unique index. The
default value is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The option is
<em>
unavailable
</em>
for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-hashed-index">
hashed
</a>
indexes.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
partialFilterExpression
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. If specified, the index only references documents that match the
filter expression. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-partial/">
Partial Indexes
</a>
for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
A filter expression can include:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
equality expressions (i.e.
<code class="leafygreen-ui-1l06pbn">
field: value
</code>
or using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/eq/#mongodb-query-op.-eq">
<code class="leafygreen-ui-1l06pbn">
$eq
</code>
</a>
operator),
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/exists/#mongodb-query-op.-exists">
<code class="leafygreen-ui-1l06pbn">
$exists: true
</code>
</a>
expression,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/gt/#mongodb-query-op.-gt">
<code class="leafygreen-ui-1l06pbn">
$gt
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/gte/#mongodb-query-op.-gte">
<code class="leafygreen-ui-1l06pbn">
$gte
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/lt/#mongodb-query-op.-lt">
<code class="leafygreen-ui-1l06pbn">
$lt
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/lte/#mongodb-query-op.-lte">
<code class="leafygreen-ui-1l06pbn">
$lte
</code>
</a>
expressions,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/type/#mongodb-query-op.-type">
<code class="leafygreen-ui-1l06pbn">
$type
</code>
</a>
expressions,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/and/#mongodb-query-op.-and">
<code class="leafygreen-ui-1l06pbn">
$and
</code>
</a>
operator,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/or/#mongodb-query-op.-or">
<code class="leafygreen-ui-1l06pbn">
$or
</code>
</a>
operator,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/in/#mongodb-query-op.-in">
<code class="leafygreen-ui-1l06pbn">
$in
</code>
</a>
operator
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If you are using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/#std-label-manual-csfle-feature">
Client-Side Field Level Encryption
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe">
Queryable Encryption
</a>
, a
<code class="leafygreen-ui-1l06pbn">
partialFilterExpression
</code>
cannot reference an
encrypted field.
</p>
<p class="leafygreen-ui-1kp3ins">
You can specify a
<code class="leafygreen-ui-1l06pbn">
partialFilterExpression
</code>
option for all MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/#std-label-index-types">
index types
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sparse
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. If
<code class="leafygreen-ui-1l06pbn">
true
</code>
, the index only references documents with the specified
field. These indexes use less space but behave differently in some
situations (particularly sorts). The default value is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-sparse/">
Sparse Indexes
</a>
for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
The following index types are sparse by default and ignore
this option:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index">
2dsphere
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
2d
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-type-text">
Text
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For a compound index that includes
<code class="leafygreen-ui-1l06pbn">
2dsphere
</code>
index key(s)
along with keys of other types, only the
<code class="leafygreen-ui-1l06pbn">
2dsphere
</code>
index
fields determine whether the index references a document.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB provides the option to create
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-partial/#std-label-index-type-partial">
partial indexes
</a>
. These
offer a superset of the functionality of sparse indexes
and are preferred instead.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Specifies a value, in seconds, as a time to live (
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-TTL">
TTL
</a>
)
to control how long MongoDB retains documents in this collection. This
option only applies to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-TTL">
TTL
</a>
indexes. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/expire-data/#std-label-ttl-collections">
Expire Data from Collections by Setting TTL
</a>
for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
If you use TTL indexes created before MongoDB 5.0, or if you want to
sync data created in MongDB 5.0 with a pre-5.0 installation, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/expire-data/#std-label-expireData-warning">
Indexes Configured Using NaN
</a>
to avoid misconfiguration issues.
</p>
<p class="leafygreen-ui-1kp3ins">
The TTL index
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
value must be within
<code class="leafygreen-ui-1l06pbn">
0
</code>
and
<code class="leafygreen-ui-1l06pbn">
2147483647
</code>
inclusive.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-createIndexes-hidden" target="_self">
<span>
hidden
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-createIndexes-hidden">
</span>
<p class="leafygreen-ui-1kp3ins">
Optional. A flag that determines whether the index is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-hidden/#std-label-index-type-hidden">
hidden
</a>
from the query planner. A
hidden index is not evaluated as part of query plan
selection.
</p>
<p class="leafygreen-ui-1kp3ins">
Default is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
storageEngine
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Allows users to configure the storage engine on a
per-index basis when creating an index.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
storageEngine
</code>
option should take the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"storageEngine: { <storage-engine-name>: <options> }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storageEngine</span>: <!-- -->{ <<!-- -->storage<!-- -->-<!-- -->engine<!-- -->-<!-- -->name<!-- -->><!-- -->: <<!-- -->options<!-- -->> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Storage engine configuration options specified when creating indexes are
validated and logged to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
during replication to
support replica sets with members that use different storage
engines.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
weights
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-type-text">
text
</a>
indexes, a document that contains
field and weight pairs. The weight is an integer ranging from 1 to
99,999 and denotes the significance of the field relative to the
other indexed fields in terms of the score. You can specify weights
for some or all the indexed fields. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/control-text-search-results/#std-label-control-text-search-results">
Assign Weights to Text Search Results on Self-Managed Deployments
</a>
to adjust the scores.
The default value is
<code class="leafygreen-ui-1l06pbn">
1
</code>
.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
default_language
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-default-language">
</span>
<p class="leafygreen-ui-1kp3ins">
Optional. For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-type-text">
text
</a>
indexes, the language that
determines the list of stop words and the rules for the stemmer and
tokenizer. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/text-search-languages/#std-label-text-search-languages">
Text Search Languages on Self-Managed Deployments
</a>
for the available
languages and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/specify-text-index-language/">
Specify the Default Language for a Text Index on Self-Managed Deployments
</a>
for more information and examples. The default value is
<code class="leafygreen-ui-1l06pbn">
english
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
language_override
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-type-text">
text
</a>
indexes, the name of the field, in
the collection's documents, that contains the override language for
the document. The default value is
<code class="leafygreen-ui-1l06pbn">
language
</code>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/specify-text-index-language/#std-label-specify-language-field-text-index-example">
Specify the Default Language for a Text Index on Self-Managed Deployments
</a>
for an example.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
textIndexVersion
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The
<code class="leafygreen-ui-1l06pbn">
text
</code>
index version number. Users can use this option to
override the default version number.
</p>
<p class="leafygreen-ui-1kp3ins">
For available versions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/text-index-versions/#std-label-text-index-versions">
Text Index Versions on Self-Managed Deployments
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
2dsphereIndexVersion
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The
<code class="leafygreen-ui-1l06pbn">
2dsphere
</code>
index version number. Users can use this option to
override the default version number.
</p>
<p class="leafygreen-ui-1kp3ins">
For the available versions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-v2">
2dsphere Indexes
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bits
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
2d
</a>
indexes, the number of precision of the
stored
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-geohash">
geohash
</a>
value of the location data.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
bits
</code>
value ranges from 1 to 32 inclusive. The default value
is
<code class="leafygreen-ui-1l06pbn">
26
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
min
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
number
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
2d
</a>
indexes, the lower inclusive boundary for
the longitude and latitude values. The default value is
<code class="leafygreen-ui-1l06pbn">
-180.0
</code>
.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
max
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
number
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
2d
</a>
indexes, the upper inclusive boundary for
the longitude and latitude values. The default value is
<code class="leafygreen-ui-1l06pbn">
180.0
</code>
.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
collation
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
</a>
for the index.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
Collation
</a>
allows users to specify
language-specific rules for string comparison, such as rules for
lettercase and accent marks.
</p>
<p class="leafygreen-ui-1kp3ins">
If you have specified a collation at the collection level, then:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you do not specify a collation when creating the index, MongoDB
creates the index with the collection's default collation.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you do specify a collation when creating the index, MongoDB
creates the index with the specified collation.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The collation option has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"collation: {\n locale: <string>,\n caseLevel: <boolean>,\n caseFirst: <string>,\n strength: <int>,\n numericOrdering: <boolean>,\n alternate: <string>,\n maxVariable: <string>,\n backwards: <boolean>\n}"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">collation: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> locale: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseLevel: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> caseFirst: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> strength: <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> numericOrdering: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> alternate: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxVariable: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> backwards: <boolean></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When specifying collation, the
<code class="leafygreen-ui-1l06pbn">
locale
</code>
field is mandatory; all
other collation fields are optional. For descriptions of the fields,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation-document-fields">
Collation Document
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-wildcardProjection-param">
</span>
<p class="leafygreen-ui-1kp3ins">
Allows users to include or exclude specific field paths from
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/#std-label-wildcard-index-core">
wildcard index
</a>
using the
<code class="leafygreen-ui-1l06pbn">
{ "$**" : 1}
</code>
key pattern. This option is only
valid if creating a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/#std-label-wildcard-index-core">
wildcard index
</a>
on
all document fields. You cannot specify this option if creating
a wildcard index on a specific field path and its subfields, e.g.
<code class="leafygreen-ui-1l06pbn">
{ "path.to.field.$**" : 1 }
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
option takes the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"wildcardProjection: {\n \"path.to.field.a\" : <value>,\n \"path.to.field.b\" : <value>\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">wildcardProjection</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"path.to.field.a"</span> <!-- -->: <<!-- -->value<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"path.to.field.b"</span> <!-- -->: <<!-- -->value<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
<value>
</code>
can be either of the following:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
or
<code class="leafygreen-ui-1l06pbn">
true
</code>
to include the field in the wildcard index.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
or
<code class="leafygreen-ui-1l06pbn">
false
</code>
to exclude the field from the wildcard index.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Wildcard indexes omit the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field by default. To include the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field in the wildcard index, you must explicitly include it
in the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"wildcardProjection\" : {\n \"_id\" : 1,\n \"<field>\" : 0|1\n }\n}","programmingLanguage":"JSON"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"wildcardProjection"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"_id"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"<field>"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span>|<span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
All of the statements in the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
document must be
either inclusion or exclusion statements. You can also include the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field with exclusion statements. This is the only exception to
the rule.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
provides the methods
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndex()
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndexes/#mongodb-method-db.collection.createIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndexes()
</code>
</a>
as wrappers for the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
command.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#considerations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="considerations">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB disallows the creation of version 0 indexes.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Names
<a class="headerlink leafygreen-ui-1kepx47" href="#index-names" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="index-names">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
command and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
helpers
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndex()
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndexes/#mongodb-method-db.collection.createIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndexes()
</code>
</a>
report an error if you
create an index with one name, and then try to create the same index
again but with another name.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"ok\" : 0,\n \"errmsg\" : \"Index with name: x_1 already exists with a different name\",\n \"code\" : 85,\n \"codeName\" : \"IndexOptionsConflict\"\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"errmsg"</span> <!-- -->: <span class="lg-highlight-string">"Index with name: x_1 already exists with a different name"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"code"</span> <!-- -->: <span class="lg-highlight-number">85</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"codeName"</span> <!-- -->: <span class="lg-highlight-string">"IndexOptionsConflict"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In previous versions, MongoDB did not create the index again, but
would return a response object with
<code class="leafygreen-ui-1l06pbn">
ok
</code>
value of
<code class="leafygreen-ui-1l06pbn">
1
</code>
and a note
that implied that the index was not recreated. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"numIndexesBefore\" : 2,\n \"numIndexesAfter\" : 2,\n \"note\" : \"all indexes already exist\",\n \"ok\" : 1\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numIndexesBefore"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numIndexesAfter"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"note"</span> <!-- -->: <span class="lg-highlight-string">"all indexes already exist"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replica Sets and Sharded Clusters
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-sets-and-sharded-clusters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replica-sets-and-sharded-clusters">
</div>
</a>
</h3>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Requires featureCompatibilityVersion 4.4+
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
in the replica set or sharded cluster
<em>
must
</em>
have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-set-fcv">
featureCompatibilityVersion
</a>
set to at
least
<code class="leafygreen-ui-1l06pbn">
4.4
</code>
to start index builds simultaneously across
replica set members.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Index builds on a replica set or sharded cluster build simultaneously across
all data-bearing replica set members. For sharded clusters, the index build
occurs only on shards containing data for the collection being indexed.
The primary requires a minimum number of data-bearing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes">
<code class="leafygreen-ui-1l06pbn">
voting
</code>
</a>
members (i.e commit quorum), including itself,
that must complete the build before marking the index as ready for
use. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations-replicated-build">
Index Builds in Replicated Environments
</a>
for more
information.
</p>
<p class="leafygreen-ui-1kp3ins">
To start an index build with a non-default commit quorum, specify the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-cmd-commitQuorum" target="_self">
<span>
commitQuorum
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setIndexCommitQuorum/#mongodb-dbcommand-dbcmd.setIndexCommitQuorum">
<code class="leafygreen-ui-1l06pbn">
setIndexCommitQuorum
</code>
</a>
command to modify the commit quorum
of an in-progress index build.
</p>
<p class="leafygreen-ui-1kp3ins">
To minimize the impact of building an index on replica sets and sharded
clusters, use a rolling index build procedure
as described on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/build-indexes-on-replica-sets/">
Rolling Index Builds on Replica Sets
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Collation and Index Types
<a class="headerlink leafygreen-ui-1kepx47" href="#collation-and-index-types" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="collation-and-index-types">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following indexes only support simple binary comparison and do
not support
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
<!-- -->
:
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-type-text">
Text
</a>
indexes
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
2d
</a>
indexes
</p>
</li>
</ul>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To create a
<code class="leafygreen-ui-1l06pbn">
text
</code>
or
<code class="leafygreen-ui-1l06pbn">
2d
</code>
index on a collection that has a
non-simple collation, you must explicitly specify
<code class="leafygreen-ui-1l06pbn">
{collation:
{locale: "simple"} }
</code>
when creating the index.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-create-indexes-stable-api">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Stable API
<a class="headerlink leafygreen-ui-1kepx47" href="#stable-api" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="stable-api">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/stable-api/#std-label-stable-api">
Stable API
</a>
V1:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot specify any of the following fields in the
<code class="leafygreen-ui-1l06pbn">
indexes
</code>
array
<!-- -->
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
background
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
bucketSize
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
sparse
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
storageEngine
</code>
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot create
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/geohaystack/#std-label-index-geohaystack-index">
geoHaystack
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-type-text">
text
</a>
indexes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The above unsupported index types are ignored by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-query-plans-query-optimization">
query planner
</a>
in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/stable-api/#std-label-stable-api-strict-client">
strict mode
</a>
. For example,
attempting to use a
<code class="leafygreen-ui-1l06pbn">
sparse
</code>
index with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.hint/#mongodb-method-cursor.hint">
<code class="leafygreen-ui-1l06pbn">
cursor.hint()
</code>
</a>
will result in the following
<code class="leafygreen-ui-1l06pbn">
BadValue
</code>
error:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"planner returned error :: caused by :: hint provided does not\ncorrespond to an existing index"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">planner returned error :: caused by :: hint provided does not</td></tr><tr class=""><td class="leafygreen-ui-7razhx">correspond to an existing index</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Concurrency
<a class="headerlink leafygreen-ui-1kepx47" href="#concurrency" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="concurrency">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
featureCompatibilityVersion
</a>
<code class="leafygreen-ui-1l06pbn">
"4.2"
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
uses an optimized build process that obtains and holds an exclusive lock on
the specified collection at the start and end of the index build. All
subsequent operations on the collection must wait until
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
releases
the exclusive lock.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
allows interleaving read and write
operations during the majority of the index build.
</p>
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
featureCompatibilityVersion
</a>
<code class="leafygreen-ui-1l06pbn">
"4.0"
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
uses the pre-4.2 index build process which by default obtains an exclusive
lock on the parent database for the entire duration of the build process. The
pre-4.2 build process blocks all operations on the database
<em>
and
</em>
all its
collections until the operation completed.
<code class="leafygreen-ui-1l06pbn">
background
</code>
indexes do not take
an exclusive lock.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on the locking behavior of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations">
Index Builds on Populated Collections
<!-- -->
.
</a>
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If a data-bearing voting node becomes unreachable and the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-cmd-commitQuorum" target="_self">
<span>
commitQuorum
</span>
</a>
is set to the
default
<code class="leafygreen-ui-1l06pbn">
votingMembers
</code>
, index builds can hang until that node
comes back online.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Memory Usage Limit
<a class="headerlink leafygreen-ui-1kepx47" href="#memory-usage-limit" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="memory-usage-limit">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
supports building one or more indexes on a
collection.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
uses a combination of memory and
temporary files on disk to complete index builds. The default limit on
memory usage for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
is 200 megabytes,
shared between all indexes built using a single
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
command. Once the memory limit is reached,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
uses temporary disk files in a subdirectory
named
<code class="leafygreen-ui-1l06pbn">
_tmp
</code>
within the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--dbpath">
<code class="leafygreen-ui-1l06pbn">
--dbpath
</code>
</a>
directory to complete the build.
</p>
<p class="leafygreen-ui-1kp3ins">
You can override the memory limit by setting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxIndexBuildMemoryUsageMegabytes">
<code class="leafygreen-ui-1l06pbn">
maxIndexBuildMemoryUsageMegabytes
</code>
</a>
server parameter.
Setting a higher memory limit may result in faster completion of index
builds. However, setting this limit too high relative to the unused RAM
on your system can result in memory exhaustion and server shutdown.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Options
<a class="headerlink leafygreen-ui-1kepx47" href="#index-options" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="index-options">
</div>
</a>
</h3>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Non-Hidden Option
<a class="headerlink leafygreen-ui-1kepx47" href="#non-hidden-option" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="non-hidden-option">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-hidden-option" target="_self">
<span>
hidden
</span>
</a>
option can be changed
without dropping and recreating the index. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-hidden-option" target="_self">
<span>
Hidden Option
<!-- -->
.
</span>
</a>
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Changing Index Options
<a class="headerlink leafygreen-ui-1kepx47" href="#changing-index-options" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="changing-index-options">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Collation options on an existing index can be updated. To change other
index options, drop the existing index with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.dropIndex/#mongodb-method-db.collection.dropIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.dropIndex()
</code>
</a>
then run
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
with the new options.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-collation-option">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Collation Option
<a class="headerlink leafygreen-ui-1kepx47" href="#collation-option" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="collation-option">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can create multiple indexes on the same key(s) with different
collations. To create indexes with the same key pattern but different
collations, you must supply unique index names.
</p>
<p class="leafygreen-ui-1kp3ins">
If you have specified a collation at the collection level, then:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you do not specify a collation when creating the index, MongoDB
creates the index with the collection's default collation.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you do specify a collation when creating the index, MongoDB
creates the index with the specified collation.
</p>
</li>
</ul>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
By specifying a collation
<code class="leafygreen-ui-1l06pbn">
strength
</code>
of
<code class="leafygreen-ui-1l06pbn">
1
</code>
or
<code class="leafygreen-ui-1l06pbn">
2
</code>
, you can
create a case-insensitive index. Index with a collation
<code class="leafygreen-ui-1l06pbn">
strength
</code>
of
<code class="leafygreen-ui-1l06pbn">
1
</code>
is both diacritic- and case-insensitive.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To use an index for string comparisons, an operation must also
specify the same collation. That is, an index with a collation
cannot support an operation that performs string comparisons on the
indexed fields if the operation specifies a different collation.
</p>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Because indexes that are configured with collation use ICU
collation keys to achieve sort order, collation-aware index keys
may be larger than index keys for indexes without collation.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For example, the collection
<code class="leafygreen-ui-1l06pbn">
myColl
</code>
has an index on a string
field
<code class="leafygreen-ui-1l06pbn">
category
</code>
with the collation locale
<code class="leafygreen-ui-1l06pbn">
"fr"
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.createIndex( { category: 1 }, { collation: { locale: \"fr\" } } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">collation</span>: <!-- -->{ <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">"fr"</span> } } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following query operation, which specifies the same collation as
the index, can use the index:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.find( { category: \"cafe\" } ).collation( { locale: \"fr\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span> } ).<span class="lg-highlight-title lg-highlight-function">collation</span>( <!-- -->{ <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">"fr"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
However, the following query operation, which by default uses the
"simple" binary collator, cannot use the index:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.find( { category: \"cafe\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For a compound index where the index prefix keys are not strings,
arrays, and embedded documents, an operation that specifies a
different collation can still use the index to support comparisons
on the index prefix keys.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the collection
<code class="leafygreen-ui-1l06pbn">
myColl
</code>
has a compound index on the
numeric fields
<code class="leafygreen-ui-1l06pbn">
score
</code>
and
<code class="leafygreen-ui-1l06pbn">
price
</code>
and the string field
<code class="leafygreen-ui-1l06pbn">
category
</code>
; the index is created with the collation locale
<code class="leafygreen-ui-1l06pbn">
"fr"
</code>
for string comparisons:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.createIndex(\n { score: 1, price: 1, category: 1 },\n { collation: { locale: \"fr\" } } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">collation</span>: <!-- -->{ <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">"fr"</span> } } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operations, which use
<code class="leafygreen-ui-1l06pbn">
"simple"
</code>
binary collation
for string comparisons, can use the index:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.find( { score: 5 } ).sort( { price: 1 } )\ndb.myColl.find( { score: 5, price: { $gt: NumberDecimal( \"10\" ) } } ).sort( { price: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">5</span> } ).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">1</span> } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">price</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>( <span class="lg-highlight-string">"10"</span> ) } } ).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operation, which uses
<code class="leafygreen-ui-1l06pbn">
"simple"
</code>
binary collation
for string comparisons on the indexed
<code class="leafygreen-ui-1l06pbn">
category
</code>
field, can use
the index to fulfill only the
<code class="leafygreen-ui-1l06pbn">
score: 5
</code>
portion of the query:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.find( { score: 5, category: \"cafe\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Matches against document keys, including embedded document keys,
use simple binary comparison. This means that a query for a key
like "foo.bár" will not match the key "foo.bar", regardless of the value you
set for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation-parameter-strength">
strength
</a>
parameter.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-hidden-option">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Hidden Option
<a class="headerlink leafygreen-ui-1kepx47" href="#hidden-option" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="hidden-option">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
To change the
<code class="leafygreen-ui-1l06pbn">
hidden
</code>
option for existing indexes, you can use the
following
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
methods:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.hideIndex/#mongodb-method-db.collection.hideIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.hideIndex()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.unhideIndex/#mongodb-method-db.collection.unhideIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.unhideIndex()
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For example,
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To change the
<code class="leafygreen-ui-1l06pbn">
hidden
</code>
option for an index to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.hideIndex/#mongodb-method-db.collection.hideIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.hideIndex()
</code>
</a>
method:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.restaurants.hideIndex( { borough: 1, ratings: 1 } );","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">restaurants</span>.<span class="lg-highlight-title lg-highlight-function">hideIndex</span>( <!-- -->{ <span class="lg-highlight-attr">borough</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">ratings</span>: <span class="lg-highlight-number">1</span> } )<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To change the
<code class="leafygreen-ui-1l06pbn">
hidden
</code>
option for an index to
<code class="leafygreen-ui-1l06pbn">
false
</code>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.unhideIndex/#mongodb-method-db.collection.unhideIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.unhideIndex()
</code>
</a>
method:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.restaurants.unhideIndex( { borough: 1, city: 1 } );","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">restaurants</span>.<span class="lg-highlight-title lg-highlight-function">unhideIndex</span>( <!-- -->{ <span class="lg-highlight-attr">borough</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-number">1</span> } )<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
</ul>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-hidden/">
Hidden Indexes
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-command-wildcard-behavior">
</span>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Wildcard Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#wildcard-indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="wildcard-indexes">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Wildcard indexes omit the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field by default. To include the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field in the wildcard index, you must explicitly include it
in the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"wildcardProjection\" : {\n \"_id\" : 1,\n \"<field>\" : 0|1\n }\n}","programmingLanguage":"JSON"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"wildcardProjection"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"_id"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"<field>"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span>|<span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
All of the statements in the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
document must be
either inclusion or exclusion statements. You can also include the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field with exclusion statements. This is the only exception to
the rule.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Wildcard indexes do not support:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/internals/#std-label-2d-index-internals">
2d (Geospatial) indexes
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index">
2dsphere (Geospatial) indexes
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-type-hashed">
Hashed indexes
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-ttl/#std-label-index-feature-ttl">
Time to Live (TTL) indexes
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-feature-text">
Text indexes
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
Unique indexes
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Wildcard indexes are
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-sparse/#std-label-index-type-sparse">
sparse
</a>
indexes. They do
not support queries when an indexed field does not exist. A wildcard
index will index the document if the wildcard field has a
<code class="leafygreen-ui-1l06pbn">
null
</code>
value.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, wildcard indexes support ascending (
<code class="leafygreen-ui-1l06pbn">
1
</code>
) and
descending (
<code class="leafygreen-ui-1l06pbn">
-1
</code>
) sort order. Earlier versions only supported
ascending order.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To learn more, see:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/#std-label-wildcard-index-core">
About Wildcard Indexes
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-command-wildcard-examples" target="_self">
<span>
Wildcard Index Examples
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions/#std-label-wildcard-index-restrictions">
Wildcard Index Restrictions
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Transactions
<a class="headerlink leafygreen-ui-1kepx47" href="#transactions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="transactions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can create collections and indexes inside a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-create-collections-indexes">
distributed
transaction
</a>
if the
transaction is
<strong class="css-4dei7l">
not
</strong>
a cross-shard write transaction.
</p>
<p class="leafygreen-ui-1kp3ins">
To use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
in a transaction, the transaction must use read
concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
. If you specify a read concern level
other than
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
, the transaction fails.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-create-collections-indexes">
Create Collections and Indexes in a Transaction
</a>
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Commit Quorum Contrasted with Write Concern
<a class="headerlink leafygreen-ui-1kepx47" href="#commit-quorum-contrasted-with-write-concern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="commit-quorum-contrasted-with-write-concern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
There are important differences between
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-cmd-commitQuorum" target="_self">
<span>
commit quorums
</span>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concerns
<!-- -->
:
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Index builds use commit quorums.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Write operations use write concerns.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Each data-bearing node in a cluster is a voting member.
</p>
<p class="leafygreen-ui-1kp3ins">
The commit quorum specifies how many data-bearing voting members, or
which voting members, including the primary, must be prepared to commit
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations-simultaneous-build">
simultaneous index build
</a>
before the primary will execute the commit.
</p>
<p class="leafygreen-ui-1kp3ins">
The write concern is the level of acknowledgment that the write has
propagated to the specified number of instances.
</p>
<div>
<p>
<em>
Changed
<!-- -->
in version
<!-- -->
8.0
</em>
:
<!-- -->
<!-- -->
The commit quorum specifies how many
nodes must be ready to finish the index build before the
primary commits the index build. In contrast, when the
primary has committed the index build, the write concern
specifies how many nodes must replicate the index build oplog
entry before the command returns success.
</p>
<p class="leafygreen-ui-1kp3ins">
In previous releases, when the primary committed the index
build, the write concern specified how many nodes must finish
the index build before the command returned success.
</p>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following command builds two indexes on the
<code class="leafygreen-ui-1l06pbn">
inventory
</code>
collection of
the
<code class="leafygreen-ui-1l06pbn">
products
</code>
database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"products\").runCommand(\n {\n createIndexes: \"inventory\",\n indexes: [\n {\n key: {\n item: 1,\n manufacturer: 1,\n model: 1\n },\n name: \"item_manufacturer_model\",\n unique: true\n },\n {\n key: {\n item: 1,\n supplier: 1,\n model: 1\n },\n name: \"item_supplier_model\",\n unique: true\n }\n ],\n writeConcern: { w: \"majority\" }\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"products"</span>).<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">createIndexes</span>: <span class="lg-highlight-string">"inventory"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">indexes</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">manufacturer</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">model</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"item_manufacturer_model"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">supplier</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">model</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"item_supplier_model"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: <!-- -->{ <span class="lg-highlight-attr">w</span>: <span class="lg-highlight-string">"majority"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When the indexes successfully finish building, MongoDB returns a results
document that includes a status of
<code class="leafygreen-ui-1l06pbn">
"ok" : 1
</code>
.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-command-wildcard-examples">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create a Wildcard Index
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-wildcard-index" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-a-wildcard-index">
</div>
</a>
</h3>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
For complete documentation on Wildcard Indexes, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/#std-label-wildcard-index-core">
Wildcard Indexes
<!-- -->
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following lists examples of wildcard index creation:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-command-wildcard-onepath" target="_self">
<span>
Create a Wildcard Index on a Single Field Path
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-command-wildcard-allpaths" target="_self">
<span>
Create a Wildcard Index on All Field Paths
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-command-wildcard-inclusion" target="_self">
<span>
Create a Wildcard Index on Multiple Specific Field Paths
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-command-wildcard-exclusion" target="_self">
<span>
Create a Wildcard Index that Excludes Multiple Specific Field Paths
</span>
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-command-wildcard-onepath">
</span>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create a Wildcard Index on a Single Field Path
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-wildcard-index-on-a-single-field-path" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-a-wildcard-index-on-a-single-field-path">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Consider a collection
<code class="leafygreen-ui-1l06pbn">
products_catalog
</code>
where documents may contain a
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field. The
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field can
contain arbitrary nested fields, including embedded
documents and arrays:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products_catalog.insertMany( [\n {\n _id : ObjectId(\"5c1d358bf383fbee028aea0b\"),\n product_name: \"Blaster Gauntlet\",\n product_attributes: {\n price: {\n cost: 299.99,\n currency: \"USD\"\n }\n }\n },\n {\n _id: ObjectId(\"5c1d358bf383fbee028aea0c\"),\n product_name: \"Super Suit\",\n product_attributes: {\n superFlight: true,\n resistance: [ \"Bludgeoning\", \"Piercing\", \"Slashing\" ]\n }\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">products_catalog</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->_id <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5c1d358bf383fbee028aea0b"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_name</span>: <span class="lg-highlight-string">"Blaster Gauntlet"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_attributes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cost</span>: <span class="lg-highlight-number">299.99</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">currency</span>: <span class="lg-highlight-string">"USD"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5c1d358bf383fbee028aea0c"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_name</span>: <span class="lg-highlight-string">"Super Suit"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_attributes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">superFlight</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">resistance</span>: <!-- -->[ <span class="lg-highlight-string">"Bludgeoning"</span>, <span class="lg-highlight-string">"Piercing"</span>, <span class="lg-highlight-string">"Slashing"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operation creates a wildcard index on the
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use inventory\ndb.runCommand(\n {\n createIndexes: \"products_catalog\",\n indexes: [\n {\n key: { \"product_attributes.$**\" : 1 },\n name: \"wildcardIndex\"\n }\n ]\n }\n)","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use inventory</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.runCommand(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> createIndexes: <span class="lg-highlight-string">"products_catalog"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> indexes: [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key: { <span class="lg-highlight-string">"product_attributes.$**"</span> : 1 },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> name: <span class="lg-highlight-string">"wildcardIndex"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
With this wildcard index, MongoDB indexes all scalar values of
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
. If the field is a nested document or array, the
wildcard index recurses into the document/array and indexes all scalar
fields in the document/array.
</p>
<p class="leafygreen-ui-1kp3ins">
The wildcard index can support arbitrary single-field queries on
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
or one of its nested fields:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products_catalog.find( { \"product_attributes.superFlight\" : true } )\ndb.products_catalog.find( { \"product_attributes.maxSpeed\" : { $gt : 20 } } )\ndb.products_catalog.find( { \"product_attributes.elements\" : { $eq: \"water\" } } )","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_attributes.superFlight"</span> : <span class="lg-highlight-literal">true</span> } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_attributes.maxSpeed"</span> : { <span class="lg-highlight-variable">$gt</span> : 20 } } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_attributes.elements"</span> : { <span class="lg-highlight-variable">$eq</span>: <span class="lg-highlight-string">"water"</span> } } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The path-specific wildcard index syntax is incompatible with the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
option. See the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-wildcardProjection-param" target="_self">
<span>
parameter documentation
</span>
</a>
for more
information.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-command-wildcard-allpaths">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create a Wildcard Index on All Field Paths
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-wildcard-index-on-all-field-paths" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-a-wildcard-index-on-all-field-paths">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Consider a collection
<code class="leafygreen-ui-1l06pbn">
products_catalog
</code>
where documents may contain a
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field. The
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field can
contain arbitrary nested fields, including embedded
documents and arrays:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products_catalog.insertMany( [\n {\n _id : ObjectId(\"5c1d358bf383fbee028aea0b\"),\n product_name: \"Blaster Gauntlet\",\n product_attributes: {\n price: {\n cost: 299.99,\n currency: \"USD\"\n }\n }\n },\n {\n _id: ObjectId(\"5c1d358bf383fbee028aea0c\"),\n product_name: \"Super Suit\",\n product_attributes: {\n superFlight: true,\n resistance: [ \"Bludgeoning\", \"Piercing\", \"Slashing\" ]\n }\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">products_catalog</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->_id <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5c1d358bf383fbee028aea0b"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_name</span>: <span class="lg-highlight-string">"Blaster Gauntlet"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_attributes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cost</span>: <span class="lg-highlight-number">299.99</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">currency</span>: <span class="lg-highlight-string">"USD"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5c1d358bf383fbee028aea0c"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_name</span>: <span class="lg-highlight-string">"Super Suit"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_attributes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">superFlight</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">resistance</span>: <!-- -->[ <span class="lg-highlight-string">"Bludgeoning"</span>, <span class="lg-highlight-string">"Piercing"</span>, <span class="lg-highlight-string">"Slashing"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operation creates a wildcard index on all scalar fields
(excluding the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field):
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use inventory\ndb.runCommand(\n {\n createIndexes: \"products_catalog\",\n indexes: [\n {\n key: { \"$**\" : 1 },\n name: \"wildcardIndex\"\n }\n ]\n }\n)","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use inventory</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.runCommand(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> createIndexes: <span class="lg-highlight-string">"products_catalog"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> indexes: [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key: { <span class="lg-highlight-string">"$**"</span> : 1 },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> name: <span class="lg-highlight-string">"wildcardIndex"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
With this wildcard index, MongoDB indexes all scalar fields for each
document in the collection. If a given field is a nested document or
array, the wildcard index recurses into the document/array and indexes
all scalar fields in the document/array.
</p>
<p class="leafygreen-ui-1kp3ins">
The created index can support queries on any arbitrary field
within documents in the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products_catalog.find( { \"product_price\" : { $lt : 25 } } )\ndb.products_catalog.find( { \"product_attributes.elements\" : { $eq: \"water\" } } )","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_price"</span> : { <span class="lg-highlight-variable">$lt</span> : 25 } } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_attributes.elements"</span> : { <span class="lg-highlight-variable">$eq</span>: <span class="lg-highlight-string">"water"</span> } } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Wildcard indexes omit the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field by default. To include the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field in the wildcard index, you must explicitly include it
in the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
document. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-wildcardProjection-param" target="_self">
<span>
parameter documentation
</span>
</a>
for
more information.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-command-wildcard-inclusion">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create a Wildcard Index on Multiple Specific Field Paths
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-wildcard-index-on-multiple-specific-field-paths" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-a-wildcard-index-on-multiple-specific-field-paths">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Consider a collection
<code class="leafygreen-ui-1l06pbn">
products_catalog
</code>
where documents may contain a
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field. The
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field can
contain arbitrary nested fields, including embedded
documents and arrays:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products_catalog.insertMany( [\n {\n _id : ObjectId(\"5c1d358bf383fbee028aea0b\"),\n product_name: \"Blaster Gauntlet\",\n product_attributes: {\n price: {\n cost: 299.99,\n currency: \"USD\"\n }\n }\n },\n {\n _id: ObjectId(\"5c1d358bf383fbee028aea0c\"),\n product_name: \"Super Suit\",\n product_attributes: {\n superFlight: true,\n resistance: [ \"Bludgeoning\", \"Piercing\", \"Slashing\" ]\n }\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">products_catalog</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->_id <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5c1d358bf383fbee028aea0b"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_name</span>: <span class="lg-highlight-string">"Blaster Gauntlet"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_attributes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cost</span>: <span class="lg-highlight-number">299.99</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">currency</span>: <span class="lg-highlight-string">"USD"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5c1d358bf383fbee028aea0c"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_name</span>: <span class="lg-highlight-string">"Super Suit"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_attributes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">superFlight</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">resistance</span>: <!-- -->[ <span class="lg-highlight-string">"Bludgeoning"</span>, <span class="lg-highlight-string">"Piercing"</span>, <span class="lg-highlight-string">"Slashing"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operation creates a wildcard index and uses
the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
option to include only scalar values of the
<code class="leafygreen-ui-1l06pbn">
product_attributes.elements
</code>
and
<code class="leafygreen-ui-1l06pbn">
product_attributes.resistance
</code>
fields in the index.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use inventory\ndb.runCommand(\n {\n createIndexes: \"products_catalog\",\n indexes: [\n {\n key: { \"$**\" : 1 },\n \"wildcardProjection\" : {\n \"product_attributes.elements\" : 1,\n \"product_attributes.resistance\" : 1\n },\n name: \"wildcardIndex\"\n }\n ]\n }\n)","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use inventory</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.runCommand(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> createIndexes: <span class="lg-highlight-string">"products_catalog"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> indexes: [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key: { <span class="lg-highlight-string">"$**"</span> : 1 },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"wildcardProjection"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"product_attributes.elements"</span> : 1,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"product_attributes.resistance"</span> : 1</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> name: <span class="lg-highlight-string">"wildcardIndex"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
While the key pattern
<code class="leafygreen-ui-1l06pbn">
"$**"
</code>
covers all fields in the document, the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
field limits the index to only the included
fields and their nested fields.
</p>
<p class="leafygreen-ui-1kp3ins">
If a field is a nested document or array, the wildcard
index recurses into the document/array and indexes all scalar fields in
the document/array.
</p>
<p class="leafygreen-ui-1kp3ins">
The created index can support queries on any scalar field
included in the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products_catalog.find( { \"product_attributes.elements\" : { $eq: \"Water\" } } )\ndb.products_catalog.find( { \"product_attributes.resistance\" : \"Bludgeoning\" } )","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_attributes.elements"</span> : { <span class="lg-highlight-variable">$eq</span>: <span class="lg-highlight-string">"Water"</span> } } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_attributes.resistance"</span> : <span class="lg-highlight-string">"Bludgeoning"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Wildcard indexes do not support mixing inclusion and exclusion
statements in the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
document
<em>
except
</em>
when
explicitly including the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field. For more information on
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-wildcardProjection-param" target="_self">
<span>
parameter documentation
</span>
</a>
.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-createIndexes-command-wildcard-exclusion">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create a Wildcard Index that Excludes Multiple Specific Field Paths
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-wildcard-index-that-excludes-multiple-specific-field-paths" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-a-wildcard-index-that-excludes-multiple-specific-field-paths">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Consider a collection
<code class="leafygreen-ui-1l06pbn">
products_catalog
</code>
where documents may contain a
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field. The
<code class="leafygreen-ui-1l06pbn">
product_attributes
</code>
field can
contain arbitrary nested fields, including embedded
documents and arrays:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products_catalog.insertMany( [\n {\n _id : ObjectId(\"5c1d358bf383fbee028aea0b\"),\n product_name: \"Blaster Gauntlet\",\n product_attributes: {\n price: {\n cost: 299.99,\n currency: \"USD\"\n }\n }\n },\n {\n _id: ObjectId(\"5c1d358bf383fbee028aea0c\"),\n product_name: \"Super Suit\",\n product_attributes: {\n superFlight: true,\n resistance: [ \"Bludgeoning\", \"Piercing\", \"Slashing\" ]\n }\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">products_catalog</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->_id <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5c1d358bf383fbee028aea0b"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_name</span>: <span class="lg-highlight-string">"Blaster Gauntlet"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_attributes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cost</span>: <span class="lg-highlight-number">299.99</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">currency</span>: <span class="lg-highlight-string">"USD"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5c1d358bf383fbee028aea0c"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_name</span>: <span class="lg-highlight-string">"Super Suit"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">product_attributes</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">superFlight</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">resistance</span>: <!-- -->[ <span class="lg-highlight-string">"Bludgeoning"</span>, <span class="lg-highlight-string">"Piercing"</span>, <span class="lg-highlight-string">"Slashing"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following operation creates a wildcard index and uses
the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
document to index all scalar fields
for each document in the collection,
<em>
excluding
</em>
the
<code class="leafygreen-ui-1l06pbn">
product_attributes.elements
</code>
and
<code class="leafygreen-ui-1l06pbn">
product_attributes.resistance
</code>
fields:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use inventory\ndb.runCommand(\n {\n createIndexes: \"products_catalog\",\n indexes: [\n {\n key: { \"$**\" : 1 },\n \"wildcardProjection\" : {\n \"product_attributes.elements\" : 0,\n \"product_attributes.resistance\" : 0\n },\n name: \"wildcardIndex\"\n }\n ]\n }\n)","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use inventory</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.runCommand(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> createIndexes: <span class="lg-highlight-string">"products_catalog"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> indexes: [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> key: { <span class="lg-highlight-string">"$**"</span> : 1 },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"wildcardProjection"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"product_attributes.elements"</span> : 0,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"product_attributes.resistance"</span> : 0</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> name: <span class="lg-highlight-string">"wildcardIndex"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
While the key pattern
<code class="leafygreen-ui-1l06pbn">
"$**"
</code>
covers all fields in the document, the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
field excludes the specified fields from the
index.
</p>
<p class="leafygreen-ui-1kp3ins">
If a field is a nested document or array, the wildcard
index recurses into the document/array and indexes all scalar fields in
the document/array.
</p>
<p class="leafygreen-ui-1kp3ins">
The created index can support queries on any scalar field
<strong>
except
</strong>
those excluded by
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products_catalog.find( { \"product_attributes.maxSpeed\" : { $gt: 25 } } )\ndb.products_catalog.find( { \"product_attributes.superStrength\" : true } )","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_attributes.maxSpeed"</span> : { <span class="lg-highlight-variable">$gt</span>: 25 } } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.products_catalog.find( { <span class="lg-highlight-string">"product_attributes.superStrength"</span> : <span class="lg-highlight-literal">true</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Wildcard indexes do not support mixing inclusion and exclusion
statements in the
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
document
<em>
except
</em>
when
explicitly including the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field. For more information on
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-wildcardProjection-param" target="_self">
<span>
parameter documentation
</span>
</a>
.
</p>
</div>
</div>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create Index With Commit Quorum
<a class="headerlink leafygreen-ui-1kepx47" href="#create-index-with-commit-quorum" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-index-with-commit-quorum">
</div>
</a>
</h3>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Requires featureCompatibilityVersion 4.4+
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
in the replica set or sharded cluster
<em>
must
</em>
have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-set-fcv">
featureCompatibilityVersion
</a>
set to at
least
<code class="leafygreen-ui-1l06pbn">
4.4
</code>
to start index builds simultaneously across
replica set members.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Index builds on a replica set or sharded cluster build simultaneously across
all data-bearing replica set members. For sharded clusters, the index build
occurs only on shards containing data for the collection being indexed.
The primary requires a minimum number of data-bearing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes">
<code class="leafygreen-ui-1l06pbn">
voting
</code>
</a>
members (i.e commit quorum), including itself,
that must complete the build before marking the index as ready for
use. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations-replicated-build">
Index Builds in Replicated Environments
</a>
for more
information.
</p>
<p class="leafygreen-ui-1kp3ins">
To set the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-cmd-commitQuorum" target="_self">
<span>
commit quorum
</span>
</a>
, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
to specify the
<code class="leafygreen-ui-1l06pbn">
commitQuorum
</code>
value.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
commitQuorum
</code>
specifies how many data-bearing voting members, or
which voting members, including the primary, must be prepared to commit
the index build before the primary will execute the commit. The default
commit quorum is
<code class="leafygreen-ui-1l06pbn">
votingMembers
</code>
, which means all data-bearing
members.
</p>
<p class="leafygreen-ui-1kp3ins">
The following operation creates an index with a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-createIndexes-cmd-commitQuorum" target="_self">
<span>
commit quorum
</span>
</a>
of
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
, or a
simple majority of data-bearing members:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"examples\").runCommand(\n {\n createIndexes: \"invoices\",\n indexes: [\n {\n key: { \"invoices\" : 1 },\n \"name\" : \"invoiceIndex\"\n }\n ],\n \"commitQuorum\" : \"majority\"\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"examples"</span>).<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">createIndexes</span>: <span class="lg-highlight-string">"invoices"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">indexes</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"invoices"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"invoiceIndex"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"commitQuorum"</span> <!-- -->: <span class="lg-highlight-string">"majority"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
marks index build as ready only after a simple
majority of data-bearing voting members "vote" to commit the index
build. For more information on index builds and the voting process, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations-replicated-build">
Index Builds in Replicated Environments
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Output
<a class="headerlink leafygreen-ui-1kepx47" href="#output" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="output">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.createIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</span>
</a>
command returns a document that indicates
the success of the operation. The document contains some but not all of
the following fields, depending on outcome:
</p>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes.createdCollectionAutomatically
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-createIndexes.createdCollectionAutomatically" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-data-createIndexes.createdCollectionAutomatically">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
true
</code>
, then the collection didn't exist and was created in the
process of creating the index.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes.numIndexesBefore
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-createIndexes.numIndexesBefore" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-data-createIndexes.numIndexesBefore">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of indexes at the start of the command.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes.numIndexesAfter
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-createIndexes.numIndexesAfter" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-data-createIndexes.numIndexesAfter">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of indexes at the end of the command.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes.ok
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-createIndexes.ok" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-data-createIndexes.ok">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A value of
<code class="leafygreen-ui-1l06pbn">
1
</code>
indicates the indexes are in place. A value of
<code class="leafygreen-ui-1l06pbn">
0
</code>
indicates an error.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes.note
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-createIndexes.note" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-data-createIndexes.note">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
This
<code class="leafygreen-ui-1l06pbn">
note
</code>
is returned if an existing index or indexes already
exist. This indicates that the index was not created or changed.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes.errmsg
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-createIndexes.errmsg" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-data-createIndexes.errmsg">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns information about any errors.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
createIndexes.code
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-createIndexes.code" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-data-createIndexes.code">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The error code representing the type of error.
</p>
</dd>
</dl>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/update-methods/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Update Methods
<a class="headerlink leafygreen-ui-1kepx47" href="#update-methods" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-methods">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
MongoDB provides the following methods for updating documents in a
collection:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:35%"/>
<col style="width:65%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Updates at most a single document that match a specified filter
even though multiple documents may match the specified filter.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#mongodb-method-db.collection.updateMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateMany()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Update all documents that match a specified filter.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.replaceOne/#mongodb-method-db.collection.replaceOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.replaceOne()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Replaces at most a single document that match a specified filter
even though multiple documents may match the specified filter.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-additional-updates">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Methods
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-methods" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="additional-methods">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following methods can also update documents from a collection:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndReplace/#mongodb-method-db.collection.findOneAndReplace">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndReplace()
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndUpdate()
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify">
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.bulkWrite/#mongodb-method-db.collection.bulkWrite">
<code class="leafygreen-ui-1l06pbn">
db.collection.bulkWrite()
</code>
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See the individual reference pages for the methods for more information
and examples.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$dateFromString (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-datefromstring--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-datefromstring--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#format-specifiers" target="_self">
<span>
Format Specifiers
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-dateFromString" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-dateFromString">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Converts a date/time string to a date object.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
expression has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $dateFromString: {\n dateString: <datestringexpression>,\n format: <formatstringexpression>,\n timezone: <tzexpression>,\n onError: <onerrorexpression>,\n onNull: <onnullexpression>\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <<!-- -->dateStringExpression<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <<!-- -->formatStringExpression<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <<!-- -->tzExpression<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">onError</span>: <<!-- -->onErrorExpression<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">onNull</span>: <<!-- -->onNullExpression<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
takes a document with the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The date/time string to convert to a date object. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Date/#mongodb-method-Date">
<code class="leafygreen-ui-1l06pbn">
Date()
</code>
</a>
for
more information on date/time formats.
</p>
<p class="leafygreen-ui-1kp3ins">
If specifying the
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
option to the operator, do not include
time zone information in the
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
format
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The date format specification of the
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
. The
<code class="leafygreen-ui-1l06pbn">
format
</code>
can be any expression
that evaluates to a string literal,
containing 0 or more format specifiers. For a list of
specifiers available, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-dateFromString-format-specifiers" target="_self">
<span>
Format Specifiers
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If unspecified,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
uses
<code class="leafygreen-ui-1l06pbn">
"%Y-%m-%dT%H:%M:%S.%LZ"
</code>
as the default format but accepts
a variety of formats and attempts to parse the
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
if
possible.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The time zone to use to format the date.
</p>
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
argument is formatted like
'2017-02-08T12:10:40.787Z', in which the 'Z' at the end indicates Zulu
time (UTC time zone), you cannot specify the
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
argument.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
<timezone>
</code>
allows for the following options and expressions
that evaluate to them:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
an
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" rel="noopener noreferrer">
<span>
Olson Timezone Identifier
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
,
such as
<code class="leafygreen-ui-1l06pbn">
"Europe/London"
</code>
or
<code class="leafygreen-ui-1l06pbn">
"America/New_York"
</code>
, or
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a UTC offset in the form:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
+/-[hh]:[mm]
</code>
, e.g.
<code class="leafygreen-ui-1l06pbn">
"+04:45"
</code>
, or
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
+/-[hh][mm]
</code>
, e.g.
<code class="leafygreen-ui-1l06pbn">
"-0530"
</code>
, or
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
+/-[hh]
</code>
, e.g.
<code class="leafygreen-ui-1l06pbn">
"+03"
</code>
, or
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The strings
<code class="leafygreen-ui-1l06pbn">
"Z"
</code>
,
<code class="leafygreen-ui-1l06pbn">
"UTC"
</code>
, or
<code class="leafygreen-ui-1l06pbn">
"GMT"
</code>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
onError
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
encounters an error while
parsing the given
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
, it outputs the result value
of the provided
<code class="leafygreen-ui-1l06pbn">
onError
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
.
This result value can be of any type.
</p>
<p class="leafygreen-ui-1kp3ins">
If you do not specify
<code class="leafygreen-ui-1l06pbn">
onError
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
throws an error if it cannot parse
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
onNull
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. If the
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
provided to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
null
</code>
or missing, it outputs
the result value of the provided
<code class="leafygreen-ui-1l06pbn">
onNull
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
.
This result value can be of any type.
</p>
<p class="leafygreen-ui-1kp3ins">
If you do not specify
<code class="leafygreen-ui-1l06pbn">
onNull
</code>
and
<code class="leafygreen-ui-1l06pbn">
dateString
</code>
is
<code class="leafygreen-ui-1l06pbn">
null
</code>
or missing, then
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
outputs
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/toDate/#mongodb-expression-exp.-toDate">
<code class="leafygreen-ui-1l06pbn">
$toDate
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/convert/#mongodb-expression-exp.-convert">
<code class="leafygreen-ui-1l06pbn">
$convert
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:60%"/>
<col style="width:40%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Results
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $dateFromString: {\n dateString: \"2017-02-08T12:10:40.787\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">"2017-02-08T12:10:40.787"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ISODate("2017-02-08T12:10:40.787Z")
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $dateFromString: {\n dateString: \"2017-02-08T12:10:40.787\",\n timezone: \"America/New_York\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">"2017-02-08T12:10:40.787"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/New_York"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ISODate("2017-02-08T17:10:40.787Z")
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $dateFromString: {\n dateString: \"2017-02-08\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">"2017-02-08"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ISODate("2017-02-08T00:00:00Z")
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $dateFromString: {\n dateString: \"oct 20 2020\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">"oct 20 2020"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ISODate("2020-10-20T00:00:00.000Z")
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $dateFromString: {\n dateString: \"06-15-2018\",\n format: \"%m-%d-%Y\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">"06-15-2018"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%m-%d-%Y"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ISODate("2018-06-15T00:00:00Z")
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $dateFromString: {\n dateString: \"15-06-2018\",\n format: \"%d-%m-%Y\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">"15-06-2018"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%d-%m-%Y"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ISODate("2018-06-15T00:00:00Z")
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $dateFromString: {\n dateString: \"WED jan 31 12:05:28 +03:30 1996\"\n} }","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">"WED jan 31 12:05:28 +03:30 1996"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ISODate("1996-01-31T08:35:28.000Z")
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-dateFromString-format-specifiers">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Format Specifiers
<a class="headerlink leafygreen-ui-1kepx47" href="#format-specifiers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="format-specifiers">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following format specifiers are available for use in the
<code class="leafygreen-ui-1l06pbn">
<formatString>
</code>
:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:60%"/>
<col style="width:20%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Specifiers
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Possible Values
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%b
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Abbreviated month (3 letters)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
jan
</code>
,
<code class="leafygreen-ui-1l06pbn">
feb
</code>
,
<code class="leafygreen-ui-1l06pbn">
mar
</code>
,
<code class="leafygreen-ui-1l06pbn">
apr
</code>
,
<code class="leafygreen-ui-1l06pbn">
may
</code>
,
<code class="leafygreen-ui-1l06pbn">
jun
</code>
,
<code class="leafygreen-ui-1l06pbn">
jul
</code>
,
<code class="leafygreen-ui-1l06pbn">
aug
</code>
,
<code class="leafygreen-ui-1l06pbn">
sep
</code>
,
<code class="leafygreen-ui-1l06pbn">
oct
</code>
,
<code class="leafygreen-ui-1l06pbn">
nov
</code>
,
<code class="leafygreen-ui-1l06pbn">
dec
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%B
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Full month name
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
january
</code>
-
<code class="leafygreen-ui-1l06pbn">
december
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%d
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Day of month (2 digits, zero padded)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
01
</code>
-
<code class="leafygreen-ui-1l06pbn">
31
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%G
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Year in ISO 8601 format
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
0000
</code>
-
<code class="leafygreen-ui-1l06pbn">
9999
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%H
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Hour (2 digits, zero padded, 24-hour clock)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
00
</code>
-
<code class="leafygreen-ui-1l06pbn">
23
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%j
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Day of year (3 digits, zero padded)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
001
</code>
-
<code class="leafygreen-ui-1l06pbn">
366
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%L
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Millisecond (3 digits, zero padded)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
000
</code>
-
<code class="leafygreen-ui-1l06pbn">
999
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%m
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Month (2 digits, zero padded)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
01
</code>
-
<code class="leafygreen-ui-1l06pbn">
12
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%M
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Minute (2 digits, zero padded)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
00
</code>
-
<code class="leafygreen-ui-1l06pbn">
59
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%S
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Second (2 digits, zero padded)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
00
</code>
-
<code class="leafygreen-ui-1l06pbn">
60
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%u
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Day of week number in ISO 8601 format (1-Monday, 7-Sunday)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
1
</code>
-
<code class="leafygreen-ui-1l06pbn">
7
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%U
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Week of year (2 digits, zero padded)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
00
</code>
-
<code class="leafygreen-ui-1l06pbn">
53
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%V
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Week of Year in ISO 8601 format
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
1
</code>
-
<code class="leafygreen-ui-1l06pbn">
53
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%w
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Day of week as an integer (0-Sunday, 6-Saturday)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
0
</code>
-
<code class="leafygreen-ui-1l06pbn">
6
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%Y
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Year (4 digits, zero padded)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
0000
</code>
-
<code class="leafygreen-ui-1l06pbn">
9999
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%z
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The timezone offset from UTC.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
+/-[hh][mm]
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%Z
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The minutes offset from UTC as a number. For example, if the
timezone offset (
<code class="leafygreen-ui-1l06pbn">
+/-[hhmm]
</code>
) was
<code class="leafygreen-ui-1l06pbn">
+0445
</code>
, the minutes
offset is
<code class="leafygreen-ui-1l06pbn">
+285
</code>
.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
+/-mmm
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%%
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Percent Character as a Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
%
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Converting Dates
<a class="headerlink leafygreen-ui-1kepx47" href="#converting-dates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="converting-dates">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Consider a collection
<code class="leafygreen-ui-1l06pbn">
logmessages
</code>
that contains the following
documents with dates.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 1, date: \"2017-02-08T12:10:40.787\", timezone: \"America/New_York\", message: \"Step 1: Started\" },\n{ _id: 2, date: \"2017-02-08\", timezone: \"-05:00\", message: \"Step 1: Ended\" },\n{ _id: 3, message: \" Step 1: Ended \" },\n{ _id: 4, date: \"2017-02-09\", timezone: \"Europe/London\", message: \"Step 2: Started\"},\n{ _id: 5, date: \"2017-02-09T03:35:02.055\", timezone: \"+0530\", message: \"Step 2: In Progress\"}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"2017-02-08T12:10:40.787"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/New_York"</span>, <span class="lg-highlight-attr">message</span>: <span class="lg-highlight-string">"Step 1: Started"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"2017-02-08"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"-05:00"</span>, <span class="lg-highlight-attr">message</span>: <span class="lg-highlight-string">"Step 1: Ended"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">message</span>: <span class="lg-highlight-string">" Step 1: Ended "</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"2017-02-09"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"Europe/London"</span>, <span class="lg-highlight-attr">message</span>: <span class="lg-highlight-string">"Step 2: Started"</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"2017-02-09T03:35:02.055"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"+0530"</span>, <span class="lg-highlight-attr">message</span>: <span class="lg-highlight-string">"Step 2: In Progress"</span>}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation uses $dateFromString to convert the
<code class="leafygreen-ui-1l06pbn">
date
</code>
value
to a date object:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.logmessages.aggregate( [ {\n $project: {\n date: {\n $dateFromString: {\n dateString: '$date',\n timezone: 'America/New_York'\n }\n }\n }\n} ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">logmessages</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">'$date'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">'America/New_York'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The above aggregation returns the following documents and converts each
<code class="leafygreen-ui-1l06pbn">
date
</code>
field
to the Eastern Time Zone:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"date\" : ISODate(\"2017-02-08T17:10:40.787Z\") }\n{ \"_id\" : 2, \"date\" : ISODate(\"2017-02-08T05:00:00Z\") }\n{ \"_id\" : 3, \"date\" : null }\n{ \"_id\" : 4, \"date\" : ISODate(\"2017-02-09T05:00:00Z\") }\n{ \"_id\" : 5, \"date\" : ISODate(\"2017-02-09T08:35:02.055Z\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-08T17:10:40.787Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-08T05:00:00Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-09T05:00:00Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-09T08:35:02.055Z"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
argument can also be provided through a document field instead of a
hard coded argument. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.logmessages.aggregate( [ {\n $project: {\n date: {\n $dateFromString: {\n dateString: '$date',\n timezone: '$timezone'\n }\n }\n }\n} ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">logmessages</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">'$date'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">'$timezone'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The above aggregation returns the following documents and converts each
<code class="leafygreen-ui-1l06pbn">
date
</code>
field
to their respective UTC representations.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"date\" : ISODate(\"2017-02-08T17:10:40.787Z\") }\n{ \"_id\" : 2, \"date\" : ISODate(\"2017-02-08T05:00:00Z\") }\n{ \"_id\" : 3, \"date\" : null }\n{ \"_id\" : 4, \"date\" : ISODate(\"2017-02-09T00:00:00Z\") }\n{ \"_id\" : 5, \"date\" : ISODate(\"2017-02-08T22:05:02.055Z\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-08T17:10:40.787Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-08T05:00:00Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-literal">null</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-09T00:00:00Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-08T22:05:02.055Z"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
onError
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#onerror" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="onerror">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If your collection contains documents with unparsable date strings,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
throws an error unless you provide an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
aggregation expression
</a>
to the optional
<code class="leafygreen-ui-1l06pbn">
onError
</code>
parameter.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, given a collection
<code class="leafygreen-ui-1l06pbn">
dates
</code>
with the following
documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"date\" : \"2017-02-08T12:10:40.787\", timezone: \"America/New_York\" },\n{ \"_id\" : 2, \"date\" : \"20177-02-09T03:35:02.055\", timezone: \"America/New_York\" }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-string">"2017-02-08T12:10:40.787"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/New_York"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-string">"20177-02-09T03:35:02.055"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/New_York"</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can use the
<code class="leafygreen-ui-1l06pbn">
onError
</code>
parameter to return the invalid date in
its original string form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.dates.aggregate( [ {\n $project: {\n date: {\n $dateFromString: {\n dateString: '$date',\n timezone: '$timezone',\n onError: '$date'\n }\n }\n }\n} ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">dates</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">'$date'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">'$timezone'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">onError</span>: <span class="lg-highlight-string">'$date'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This returns the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"date\" : ISODate(\"2017-02-08T17:10:40.787Z\") }\n{ \"_id\" : 2, \"date\" : \"20177-02-09T03:35:02.055\" }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-08T17:10:40.787Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-string">"20177-02-09T03:35:02.055"</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
onNull
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#onnull" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="onnull">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If your collection contains documents with
<code class="leafygreen-ui-1l06pbn">
null
</code>
date strings,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
unless you provide an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
aggregation expression
</a>
to the optional
<code class="leafygreen-ui-1l06pbn">
onNull
</code>
parameter.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, given a collection
<code class="leafygreen-ui-1l06pbn">
dates
</code>
with the following
documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"date\" : \"2017-02-08T12:10:40.787\", timezone: \"America/New_York\" },\n{ \"_id\" : 2, \"date\" : null, timezone: \"America/New_York\" }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-string">"2017-02-08T12:10:40.787"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/New_York"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"America/New_York"</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can use the
<code class="leafygreen-ui-1l06pbn">
onNull
</code>
parameter to have
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateFromString" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateFromString
</code>
</span>
</a>
return a date representing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-unix-epoch">
unix epoch
</a>
instead of
<code class="leafygreen-ui-1l06pbn">
null
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.dates.aggregate( [ {\n $project: {\n date: {\n $dateFromString: {\n dateString: '$date',\n timezone: '$timezone',\n onNull: new Date(0)\n }\n }\n }\n} ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">dates</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateFromString</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dateString</span>: <span class="lg-highlight-string">'$date'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">'$timezone'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">onNull</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-number">0</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This returns the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"date\" : ISODate(\"2017-02-08T17:10:40.787Z\") }\n{ \"_id\" : 2, \"date\" : ISODate(\"1970-01-01T00:00:00Z\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2017-02-08T17:10:40.787Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"1970-01-01T00:00:00Z"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$subtract (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-subtract--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-subtract--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$subtract
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-subtract" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-subtract">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Subtracts two numbers to return the difference, or two dates to
return the difference in milliseconds, or a date and a number in
milliseconds to return the resulting date.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-subtract" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$subtract
</code>
</span>
</a>
expression has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $subtract: [ <expression1>, <expression2> ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$subtract</span>: <!-- -->[ <<!-- -->expression1<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->expression2<!-- -->> <!-- -->] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The second argument is subtracted from the first argument.
</p>
<p class="leafygreen-ui-1kp3ins">
The arguments can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
as long as they resolve to numbers
and/or dates. To subtract a number from a date, the date must be the
first argument. For more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When input types are mixed,
<code class="leafygreen-ui-1l06pbn">
$subtract
</code>
promotes the smaller input
type to the larger of the two. A type is considered larger when it
represents a wider range of values. The order of numeric types from
smallest to largest is: integer → long → double → decimal
</p>
<p class="leafygreen-ui-1kp3ins">
The larger of the input types also determines the result type unless
the operation overflows and is beyond the range represented by that
larger data type. In cases of overflow,
<code class="leafygreen-ui-1l06pbn">
$subtract
</code>
promotes the
result according to the following order:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the larger input type is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Int32">
<code class="leafygreen-ui-1l06pbn">
integer
</code>
</a>
, the result type
is promoted to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Int64">
<code class="leafygreen-ui-1l06pbn">
long
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the larger input type is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Int64">
<code class="leafygreen-ui-1l06pbn">
long
</code>
</a>
, the result type is
promoted to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Double">
<code class="leafygreen-ui-1l06pbn">
double
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the larger type is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Double">
<code class="leafygreen-ui-1l06pbn">
double
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Decimal128">
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
</a>
, the overflow result is represented
as + or - infinity. There is no type promotion of the result.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
When mixing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Date">
<code class="leafygreen-ui-1l06pbn">
Date
</code>
</a>
and non-integer operands,
<code class="leafygreen-ui-1l06pbn">
$subtract
</code>
rounds the non-integer value to the nearest integer
before performing the operation.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider a
<code class="leafygreen-ui-1l06pbn">
sales
</code>
collection with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.insertMany([\n { \"_id\" : 1, \"item\" : \"abc\", \"price\" : 10, \"fee\" : 2, \"discount\" : 5, \"date\" : ISODate(\"2014-03-01T08:00:00Z\") },\n { \"_id\" : 2, \"item\" : \"jkl\", \"price\" : 20, \"fee\" : 1, \"discount\" : 2, \"date\" : ISODate(\"2014-03-01T09:00:00Z\") }\n])","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"fee"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"discount"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-03-01T08:00:00Z"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"jkl"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"fee"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"discount"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-03-01T09:00:00Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Subtract Numbers
<a class="headerlink leafygreen-ui-1kepx47" href="#subtract-numbers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="subtract-numbers">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following aggregation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-subtract" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$subtract
</code>
</span>
</a>
expression
to compute the
<code class="leafygreen-ui-1l06pbn">
total
</code>
by subtracting the
<code class="leafygreen-ui-1l06pbn">
discount
</code>
from the
subtotal of
<code class="leafygreen-ui-1l06pbn">
price
</code>
and
<code class="leafygreen-ui-1l06pbn">
fee
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.aggregate( [ { $project: { item: 1, total: { $subtract: [ { $add: [ \"$price\", \"$fee\" ] }, \"$discount\" ] } } } ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">total</span>: <!-- -->{ <span class="lg-highlight-attr">$subtract</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <span class="lg-highlight-string">"$price"</span>, <span class="lg-highlight-string">"$fee"</span> ] }<!-- -->, <span class="lg-highlight-string">"$discount"</span> ] } } } ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following results:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"abc\", \"total\" : 7 }\n{ \"_id\" : 2, \"item\" : \"jkl\", \"total\" : 19 }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">7</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"jkl"</span>, <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">19</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Subtract Two Dates
<a class="headerlink leafygreen-ui-1kepx47" href="#subtract-two-dates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="subtract-two-dates">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following aggregation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-subtract" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$subtract
</code>
</span>
</a>
expression
to subtract
<code class="leafygreen-ui-1l06pbn">
$date
</code>
from the current date, using the system
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.NOW">
<code class="leafygreen-ui-1l06pbn">
NOW
</code>
</a>
and returns the difference in milliseconds:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.aggregate( [ { $project: { item: 1, dateDifference: { $subtract: [ \"$$NOW\", \"$date\" ] } } } ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">dateDifference</span>: <!-- -->{ <span class="lg-highlight-attr">$subtract</span>: <!-- -->[ <span class="lg-highlight-string">"$$NOW"</span>, <span class="lg-highlight-string">"$date"</span> ] } } } ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Alternatively, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Date/#mongodb-method-Date">
<code class="leafygreen-ui-1l06pbn">
Date()
</code>
</a>
for the current date:s
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.aggregate( [ { $project: { item: 1, dateDifference: { $subtract: [ new Date(), \"$date\" ] } } } ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">dateDifference</span>: <!-- -->{ <span class="lg-highlight-attr">$subtract</span>: <!-- -->[ <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<!-- -->)<!-- -->, <span class="lg-highlight-string">"$date"</span> ] } } } ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Both operations return documents that resemble the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"abc\", \"dateDifference\" : NumberLong(\"186136746187\") }\n{ \"_id\" : 2, \"item\" : \"jkl\", \"dateDifference\" : NumberLong(\"186133146187\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-string">"dateDifference"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"186136746187"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"jkl"</span>, <span class="lg-highlight-string">"dateDifference"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"186133146187"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Subtract Milliseconds from a Date
<a class="headerlink leafygreen-ui-1kepx47" href="#subtract-milliseconds-from-a-date" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="subtract-milliseconds-from-a-date">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following aggregation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-subtract" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$subtract
</code>
</span>
</a>
expression
to subtract 5 * 60 * 1000 milliseconds (5 minutes) from the "$date"
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.aggregate( [ { $project: { item: 1, dateDifference: { $subtract: [ \"$date\", 5 * 60 * 1000 ] } } } ] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">sales</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">dateDifference</span>: <!-- -->{ <span class="lg-highlight-attr">$subtract</span>: <!-- -->[ <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-number">5</span> <!-- -->* <span class="lg-highlight-number">60</span> <!-- -->* <span class="lg-highlight-number">1000</span> ] } } } ] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following results:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"abc\", \"dateDifference\" : ISODate(\"2014-03-01T07:55:00Z\") }\n{ \"_id\" : 2, \"item\" : \"jkl\", \"dateDifference\" : ISODate(\"2014-03-01T08:55:00Z\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-string">"dateDifference"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-03-01T07:55:00Z"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"jkl"</span>, <span class="lg-highlight-string">"dateDifference"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2014-03-01T08:55:00Z"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/administration/health-managers/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Configure Self-Managed Sharded Cluster Health with Health Managers
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-self-managed-sharded-cluster-health-with-health-managers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configure-self-managed-sharded-cluster-health-with-health-managers">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#active-fault-duration" target="_self">
<span>
Active Fault Duration
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#progress-monitor" target="_self">
<span>
Progress Monitor
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
This document describes how to use
<!-- -->
Health Managers
<!-- -->
to monitor and manage sharded
cluster health issues.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
A
<!-- -->
Health Manager
<!-- -->
runs health checks on a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-health-manager-facet">
health manager facet
</a>
at a specified
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-health-managers-intensity-levels" target="_self">
<span>
intensity level
</span>
</a>
.
<!-- -->
Health Manager
<!-- -->
checks
run at specified time intervals. A
<!-- -->
Health Manager
<!-- -->
can be configured to
move a failing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
out of a cluster automatically.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-health-managers-progress-monitor" target="_self">
<span>
Progress Monitor
</span>
</a>
ensures
that
<!-- -->
Health Manager
<!-- -->
checks do not become stuck or unresponsive.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-health-managers-facets">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Health Manager Facets
<a class="headerlink leafygreen-ui-1kepx47" href="#health-manager-facets" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="health-manager-facets">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following table shows the available
<!-- -->
Health Manager
<!-- -->
facets:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:25%"/>
<col style="width:75%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Facet
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
What the Health Observer Checks
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
configServer
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Cluster health issues related to connectivity to the config server.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
dns
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Cluster health issues related to DNS availability and functionality.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ldap
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Cluster health issues related to LDAP availability and functionality.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-health-managers-intensity-levels">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Health Manager Intensity Levels
<a class="headerlink leafygreen-ui-1kepx47" href="#health-manager-intensity-levels" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="health-manager-intensity-levels">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following table shows the available
<!-- -->
Health Manager
<!-- -->
intensity levels:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:25%"/>
<col style="width:75%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Intensity Level
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
critical
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<!-- -->
Health Manager
<!-- -->
on this facet is enabled and has the ability to move the
failing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
out of the cluster if an error
occurs. The
<!-- -->
Health Manager
<!-- -->
waits the amount of time specified by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.activeFaultDurationSecs">
<code class="leafygreen-ui-1l06pbn">
activeFaultDurationSecs
</code>
</a>
before stopping and moving
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
out of the cluster automatically.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
non-critical
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<!-- -->
Health Manager
<!-- -->
on this facet is enabled and logs
errors, but the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
remains in the cluster if
errors are encountered.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
off
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<!-- -->
Health Manager
<!-- -->
on this facet is disabled. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
does not perform any health checks on this facet. This
is the default intensity level.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-health-managers-active-fault">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Active Fault Duration
<a class="headerlink leafygreen-ui-1kepx47" href="#active-fault-duration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="active-fault-duration">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When a failure is detected and the
<!-- -->
Health Manager
<!-- -->
intensity level
is set to
<code class="leafygreen-ui-1l06pbn">
critical
</code>
, the
<!-- -->
Health Manager
<!-- -->
waits the amount of time specified by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.activeFaultDurationSecs">
<code class="leafygreen-ui-1l06pbn">
activeFaultDurationSecs
</code>
</a>
before stopping and moving the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
out of the cluster automatically.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-health-managers-progress-monitor">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Progress Monitor
<a class="headerlink leafygreen-ui-1kepx47" href="#progress-monitor" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="progress-monitor">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-health-managers-progress-monitor" target="_self">
<span>
Progress Monitor
</span>
</a>
runs tests
to ensure that
<!-- -->
Health Manager
<!-- -->
checks do not become stuck or
unresponsive. Progress Monitor runs these tests in intervals specified
by
<code class="leafygreen-ui-1l06pbn">
interval
</code>
. If a health check begins but does not complete within
the timeout given by
<code class="leafygreen-ui-1l06pbn">
deadline
</code>
, Progress Monitor stops the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
and removes it from the cluster.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
progressMonitor
</code>
Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#progressmonitor-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="progressmonitor-fields">
</div>
</a>
</h3>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:25%"/>
<col style="width:50%"/>
<col style="width:25%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Units
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
interval
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
How often to ensure
<!-- -->
Health Managers
<!-- -->
are not stuck or unresponsive.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Milliseconds
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
deadline
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Timeout before automatically failing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
if a
<!-- -->
Health Manager
<!-- -->
check is not making progress.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Seconds
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following examples show how
<!-- -->
Health Managers
<!-- -->
can be configured. For
information on
<!-- -->
Health Manager
<!-- -->
parameters, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#std-label-health-manager-parameters">
Health Manager Parameters
<!-- -->
.
</a>
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Intensity
<a class="headerlink leafygreen-ui-1kepx47" href="#intensity" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="intensity">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For example, to set the
<code class="leafygreen-ui-1l06pbn">
dns
</code>
<!-- -->
Health Manager
<!-- -->
facet to the
<code class="leafygreen-ui-1l06pbn">
critical
</code>
intensity level, issue the following at startup:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongos --setParameter 'healthMonitoringIntensities={ values:[ { type:\"dns\", intensity: \"critical\"} ] }'","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongos --setParameter <span class="lg-highlight-string">'healthMonitoringIntensities={ values:[ { type:"dns", intensity: "critical"} ] }'</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Or if using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
command in a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
session that is connected to a running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n setParameter: 1,\n healthMonitoringIntensities: { values: [ { type: \"dns\", intensity: \"critical\" } ] } } )\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setParameter</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">healthMonitoringIntensities</span>: <!-- -->{ <span class="lg-highlight-attr">values</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"dns"</span>, <span class="lg-highlight-attr">intensity</span>: <span class="lg-highlight-string">"critical"</span> } ] } } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Parameters set with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
do not persist across
restarts. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#std-label-setParameter-commands-not-persistent">
setParameter page
</a>
for details.
</p>
<p class="leafygreen-ui-1kp3ins">
To make this setting persistent, set
<code class="leafygreen-ui-1l06pbn">
healthMonitoringIntensities
</code>
in your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
mongos config file
</a>
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
option as in the following example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"setParameter:\n healthMonitoringIntensities: \"{ values:[ { type:\\\"dns\\\", intensity: \\\"critical\\\"} ] }\"","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">setParameter:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">healthMonitoringIntensities:</span> <span class="lg-highlight-string">"{ values:[ { type:</span><span class="lg-highlight-string">\"</span><span class="lg-highlight-string">dns</span><span class="lg-highlight-string">\"</span><span class="lg-highlight-string">, intensity: </span><span class="lg-highlight-string">\"</span><span class="lg-highlight-string">critical</span><span class="lg-highlight-string">\"</span><span class="lg-highlight-string">} ] }"</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
healthMonitoringIntensities
</code>
accepts an array of documents,
<code class="leafygreen-ui-1l06pbn">
values
</code>
. Each document in
<code class="leafygreen-ui-1l06pbn">
values
</code>
takes two fields:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
type
</code>
, the
<!-- -->
Health Manager
<!-- -->
facet
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
intensity
</code>
, the intensity level
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.healthMonitoringIntensities">
<code class="leafygreen-ui-1l06pbn">
healthMonitoringIntensities
</code>
</a>
for details.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Intervals
<a class="headerlink leafygreen-ui-1kepx47" href="#intervals" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="intervals">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For example, to set the
<code class="leafygreen-ui-1l06pbn">
ldap
</code>
<!-- -->
Health Manager
<!-- -->
facet to the
run health checks every 30 seconds, issue the following at startup:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongos --setParameter 'healthMonitoringIntervals={ values:[ { type:\"ldap\", interval: \"30000\"} ] }'","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongos --setParameter <span class="lg-highlight-string">'healthMonitoringIntervals={ values:[ { type:"ldap", interval: "30000"} ] }'</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Or if using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
command in a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
session that is connected to a running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n setParameter: 1,\n healthMonitoringIntervals: { values: [ { type: \"ldap\", interval: \"30000\" } ] } } )\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setParameter</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">healthMonitoringIntervals</span>: <!-- -->{ <span class="lg-highlight-attr">values</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"ldap"</span>, <span class="lg-highlight-attr">interval</span>: <span class="lg-highlight-string">"30000"</span> } ] } } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Parameters set with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
do not persist across
restarts. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#std-label-setParameter-commands-not-persistent">
setParameter page
</a>
for details.
</p>
<p class="leafygreen-ui-1kp3ins">
To make this setting persistent, set
<code class="leafygreen-ui-1l06pbn">
healthMonitoringIntervals
</code>
in your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
mongos config file
</a>
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
option as in the following example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"setParameter:\n healthMonitoringIntervals: \"{ values: [{type: \\\"ldap\\\", interval: 200}] }\"","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">setParameter:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">healthMonitoringIntervals:</span> <span class="lg-highlight-string">"{ values: [{type: </span><span class="lg-highlight-string">\"</span><span class="lg-highlight-string">ldap</span><span class="lg-highlight-string">\"</span><span class="lg-highlight-string">, interval: 200}] }"</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
healthMonitoringIntervals
</code>
accepts an array of documents,
<code class="leafygreen-ui-1l06pbn">
values
</code>
. Each document in
<code class="leafygreen-ui-1l06pbn">
values
</code>
takes two fields:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
type
</code>
, the
<!-- -->
Health Manager
<!-- -->
facet
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
interval
</code>
, the time interval it runs at, in milliseconds
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.healthMonitoringIntervals">
<code class="leafygreen-ui-1l06pbn">
healthMonitoringIntervals
</code>
</a>
for details.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Active Fault Duration
<a class="headerlink leafygreen-ui-1kepx47" href="#active-fault-duration-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="active-fault-duration-1">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For example, to set the duration from failure to crash to five
minutes, issue the following at startup:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongos --setParameter activeFaultDurationSecs=300","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongos --setParameter activeFaultDurationSecs=300</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Or if using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
command in a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
session that is connected to a running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n setParameter: 1,\n activeFaultDurationSecs: 300\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setParameter</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">activeFaultDurationSecs</span>: <span class="lg-highlight-number">300</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Parameters set with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
do not persist across
restarts. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#std-label-setParameter-commands-not-persistent">
setParameter page
</a>
for details.
</p>
<p class="leafygreen-ui-1kp3ins">
To make this setting persistent, set
<code class="leafygreen-ui-1l06pbn">
activeFaultDurationSecs
</code>
in your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
mongos config file
</a>
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
option as in the following example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"setParameter:\n activeFaultDurationSecs: 300","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">setParameter:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">activeFaultDurationSecs:</span> <span class="lg-highlight-number">300</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.activeFaultDurationSecs">
<code class="leafygreen-ui-1l06pbn">
activeFaultDurationSecs
</code>
</a>
for details.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Progress Monitor
<a class="headerlink leafygreen-ui-1kepx47" href="#progress-monitor-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="progress-monitor-1">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-health-managers-progress-monitor" target="_self">
<span>
Progress Monitor
</span>
</a>
runs tests
to ensure that
<!-- -->
Health Manager
<!-- -->
checks do not become stuck or
unresponsive. Progress Monitor runs these tests in intervals specified
by
<code class="leafygreen-ui-1l06pbn">
interval
</code>
. If a health check begins but does not complete within
the timeout given by
<code class="leafygreen-ui-1l06pbn">
deadline
</code>
, Progress Monitor stops the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-label-mongos">
mongos
</a>
and removes it from the cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
To set the
<code class="leafygreen-ui-1l06pbn">
interval
</code>
to 1000 milliseconds and the
<code class="leafygreen-ui-1l06pbn">
deadline
</code>
to 300 seconds, issue the following at startup:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongos --setParameter 'progressMonitor={\"interval\": 1000, \"deadline\": 300}'","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongos --setParameter <span class="lg-highlight-string">'progressMonitor={"interval": 1000, "deadline": 300}'</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Or if using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
command in a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
session that is connected to a running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n setParameter: 1,\n progressMonitor: { interval: 1000, deadline: 300 } )\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setParameter</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">progressMonitor</span>: <!-- -->{ <span class="lg-highlight-attr">interval</span>: <span class="lg-highlight-number">1000</span>, <span class="lg-highlight-attr">deadline</span>: <span class="lg-highlight-number">300</span> } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Parameters set with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
do not persist across
restarts. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#std-label-setParameter-commands-not-persistent">
setParameter page
</a>
for details.
</p>
<p class="leafygreen-ui-1kp3ins">
To make this setting persistent, set
<code class="leafygreen-ui-1l06pbn">
progressMonitor
</code>
in your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#std-label-configuration-options">
mongos config file
</a>
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
option as in the following example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"setParameter:\n progressMonitor: \"{ interval: 1000, deadline: 300 }\"","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">setParameter:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">progressMonitor:</span> <span class="lg-highlight-string">"{ interval: 1000, deadline: 300 }"</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.progressMonitor">
<code class="leafygreen-ui-1l06pbn">
progressMonitor
</code>
</a>
for details.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/sh.addShard/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
sh.addShard()
<a class="headerlink leafygreen-ui-1kepx47" href="#sh.addshard--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sh.addshard--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self">
<span>
Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
sh.addShard(<url>)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.addShard" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-sh.addShard">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Adds a shard replica set to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster
</a>
. This method
must be run on a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for database commands or language-specific drivers,
such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For the database command, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/addShard/#mongodb-dbcommand-dbcmd.addShard">
<code class="leafygreen-ui-1l06pbn">
addShard
</code>
</a>
command
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addShard" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.addShard()
</code>
</span>
</a>
method has the following parameter:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Parameter
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
host
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The replica set name, hostname, and port of at least one member of
the shard's replica set. Any additional replica set member hostnames
must be comma separated. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"<replica_set>/<hostname><:port>,<hostname><:port>, ...","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><replica_set>/<hostname><:port>,<hostname><:port>, ...</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addShard" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.addShard()
</code>
</span>
</a>
method has the following prototype form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShard(\"<replica_set>/<hostname><:port>\")","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">addShard</span>(<span class="lg-highlight-string">"<replica_set>/<hostname><:port>"</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Do not use
<code class="leafygreen-ui-1l06pbn">
localhost
</code>
for the hostname unless your
config server
is also running on
<code class="leafygreen-ui-1l06pbn">
localhost
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
installed from official
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-debian/">
.deb
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/install-mongodb-on-red-hat/">
.rpm
</a>
packages
have the
<code class="leafygreen-ui-1l06pbn">
bind_ip
</code>
configuration set to
<code class="leafygreen-ui-1l06pbn">
127.0.0.1
</code>
by
default.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/addShard/#mongodb-dbcommand-dbcmd.addShard">
<code class="leafygreen-ui-1l06pbn">
addShard
</code>
</a>
command and its helper
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addShard" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.addShard()
</code>
.
</span>
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This method is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is not supported in serverless instances.
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#considerations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="considerations">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Balancing
<a class="headerlink leafygreen-ui-1kepx47" href="#balancing" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="balancing">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When you add a shard to a sharded cluster, you affect the balance of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
chunks
</a>
among the shards of a cluster for all existing sharded
collections. The balancer will begin migrating chunks so that the
cluster will achieve balance. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-internals-balancing">
Balancer Internals
</a>
for
more information.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Hidden Members
<a class="headerlink leafygreen-ui-1kepx47" href="#hidden-members" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="hidden-members">
</div>
</a>
</h3>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
You cannot include a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-hidden-member/#std-label-replica-set-hidden-configuration">
hidden member
</a>
in the seed list provided to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addShard" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.addShard()
</code>
</span>
</a>
.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
DDL Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#ddl-operations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ddl-operations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you run
<code class="leafygreen-ui-1l06pbn">
sh.addShard
</code>
while your cluster executes a DDL operation
(operation that modifies a collection such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/reshardCollection/#mongodb-dbcommand-dbcmd.reshardCollection">
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
</a>
),
<code class="leafygreen-ui-1l06pbn">
sh.addShard
</code>
only executes after the
concurrent DDL operation finishes.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To add a shard, specify the name of the replica set and
the hostname of at least one member of the replica set, as a seed. If
you specify additional hostnames, all must be members of the same
replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example adds a replica set named
<code class="leafygreen-ui-1l06pbn">
repl0
</code>
and specifies
one member of the replica set:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShard(\"repl0/mongodb3.example.net:27327\")","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">addShard</span>(<span class="lg-highlight-string">"repl0/mongodb3.example.net:27327"</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/appendOplogNote/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
appendOplogNote
<a class="headerlink leafygreen-ui-1kepx47" href="#appendoplognote" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="appendoplognote">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
appendOplogNote
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.appendOplogNote" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.appendOplogNote">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Writes a non-operational entry to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is not supported in M0, M2, and M5 clusters.
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can only run the
<code class="leafygreen-ui-1l06pbn">
appendOplogNote
</code>
command on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
<p class="leafygreen-ui-1kp3ins">
The command has this syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n appendOplogNote: 1,\n data: <document>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">appendOplogNote</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">data</span>: <<span class="lg-highlight-variable lg-highlight-language">document</span>></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h3>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
appendOplogNote
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
any
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Set to any value.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
data
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The document to append to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
<!-- -->
.
</a>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To append a non-operational entry to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.adminCommand/#mongodb-method-db.adminCommand">
<code class="leafygreen-ui-1l06pbn">
db.adminCommand()
</code>
</a>
method:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n appendOplogNote: 1,\n data: {\n msg: \"Appending test message to oplog\"\n }\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">appendOplogNote</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">data</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">msg</span>: <span class="lg-highlight-string">"Appending test message to oplog"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Example
<code class="leafygreen-ui-1l06pbn">
oplog
</code>
entry:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n op: \"n\",\n ns: \"\",\n o: {\n msg: \"Appending test message to oplog\"\n },\n ts: Timestamp({ t: 1689177321, i: 1 }),\n t: Long(\"1\"),\n v: Long(\"2\"),\n wall: ISODate(\"2023-07-12T15:55:21.180Z\")\n}","programmingLanguage":"JSON"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> op<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"n"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ns<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">""</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> o<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> msg<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Appending test message to oplog"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ts<span class="lg-highlight-punctuation">:</span> Timestamp(<span class="lg-highlight-punctuation">{</span> t<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1689177321</span><span class="lg-highlight-punctuation">,</span> i<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">1</span> <span class="lg-highlight-punctuation">}</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> t<span class="lg-highlight-punctuation">:</span> Long(<span class="lg-highlight-string">"1"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> v<span class="lg-highlight-punctuation">:</span> Long(<span class="lg-highlight-string">"2"</span>)<span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> wall<span class="lg-highlight-punctuation">:</span> ISODate(<span class="lg-highlight-string">"2023-07-12T15:55:21.180Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">}</span></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/update/positional-all/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$[]
<a class="headerlink leafygreen-ui-1kepx47" href="#---" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="---">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="update">
<dt>
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-update-up.---" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-update-up.---">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The all positional operator
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
indicates that the update
operator should modify all elements in the specified array field.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
operator has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ <update>: { \"<array>.$[]\" : value } }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <!-- --><update operator>: { "<array>.$[]" : value } }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Use in update operations, e.g.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify">
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</a>
, to modify all array
elements for the document or documents that match the query
condition. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.updateOne(\n { <query> },\n { <update>: { \"<array>.$[]\" : value } }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- --><query conditions> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <update operator>: { "<array>.$[]" : value } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For an example, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-positional-update-all" target="_self">
<span>
Update All Elements in an Array
<!-- -->
.
</span>
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, update operators process document fields with
string-based names in lexicographic order. Fields with numeric names are
processed in numeric order. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/#std-label-update-operators-processing-order">
Update Operators Behavior
</a>
for details.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
upsert
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#upsert" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upsert">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
upsert
</a>
operation results in an insert, the
<code class="leafygreen-ui-1l06pbn">
query
</code>
must
include an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/query-arrays/#std-label-array-match-exact">
exact equality match
</a>
on the array
field in order to use the
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
positional operator in the update
statement.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following upsert operation, which uses
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
in the
update document, specifies an exact equality match condition on the
array field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.updateOne(\n { myArray: [ 5, 8 ] },\n { $set: { \"myArray.$[]\": 10 } },\n { upsert: true }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">myArray</span>: <!-- -->[ <span class="lg-highlight-number">5</span>, <span class="lg-highlight-number">8</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"myArray.$[]"</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If no such document exists, the operation would result in an insertion
of the following document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : ObjectId(...), \"myArray\" : [ 10, 10 ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<!-- -->...<!-- -->)<!-- -->, <span class="lg-highlight-string">"myArray"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">10</span>, <span class="lg-highlight-number">10</span> ] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If the upsert operation did not include an exact equality match and no
matching documents were found to update, the upsert operation would
error.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following operations would error if no matching
documents were found to update:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.emptyCollection.updateOne(\n { },\n { $set: { \"myArray.$[]\": 10 } },\n { upsert: true }\n)\n\ndb.emptyCollection.updateOne(\n { myArray: 5 },\n { $set: { \"myArray.$[]\": 10 } },\n { upsert: true }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">emptyCollection</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"myArray.$[]"</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">emptyCollection</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">myArray</span>: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"myArray.$[]"</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Nested Arrays
<a class="headerlink leafygreen-ui-1kepx47" href="#nested-arrays" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="nested-arrays">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
operator can be used for queries that traverse more than
one array and nested arrays.
</p>
<p class="leafygreen-ui-1kp3ins">
For an example, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-position-nested-arrays" target="_self">
<span>
Update Nested Arrays in Conjunction with
<code class="leafygreen-ui-1l06pbn">
$[<identifier>]
</code>
.
</span>
</a>
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-positional-update-all">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update All Elements in an Array
<a class="headerlink leafygreen-ui-1kepx47" href="#update-all-elements-in-an-array" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-all-elements-in-an-array">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create the
<code class="leafygreen-ui-1l06pbn">
students
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.insertMany( [\n { \"_id\" : 1, \"grades\" : [ 85, 82, 80 ] },\n { \"_id\" : 2, \"grades\" : [ 88, 90, 92 ] },\n { \"_id\" : 3, \"grades\" : [ 85, 100, 90 ] }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">85</span>, <span class="lg-highlight-number">82</span>, <span class="lg-highlight-number">80</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">88</span>, <span class="lg-highlight-number">90</span>, <span class="lg-highlight-number">92</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">85</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">90</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To increment all elements in the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
array by
<code class="leafygreen-ui-1l06pbn">
10
</code>
for all
documents in the collection, use the all positional
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.---" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
</span>
</a>
operator:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.updateMany(\n { },\n { $inc: { \"grades.$[]\": 10 } },\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students</span>.<span class="lg-highlight-title lg-highlight-function">updateMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[]"</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The all positional
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.---" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
</span>
</a>
operator acts as a placeholder for all
elements in the array field.
</p>
<p class="leafygreen-ui-1kp3ins">
After the operation, the
<code class="leafygreen-ui-1l06pbn">
students
</code>
collection contains the following
documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"grades\" : [ 95, 92, 90 ] }\n{ \"_id\" : 2, \"grades\" : [ 98, 100, 102 ] }\n{ \"_id\" : 3, \"grades\" : [ 95, 110, 100 ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">92</span>, <span class="lg-highlight-number">90</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">98</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">102</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">110</span>, <span class="lg-highlight-number">100</span> ] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update All Documents in an Array
<a class="headerlink leafygreen-ui-1kepx47" href="#update-all-documents-in-an-array" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-all-documents-in-an-array">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.---" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
</span>
</a>
positional operator facilitates updates to arrays
that contain embedded documents. To access the fields in the embedded
documents, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/document/#std-label-document-dot-notation">
dot notation
</a>
with the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.---" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
</span>
</a>
operator.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.updateOne(\n { <query> },\n { <update>: { \"array.$[].field\" : value } }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- --><query selector> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { <update operator>: { "array.$[].field" : value } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Create the
<code class="leafygreen-ui-1l06pbn">
students2
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.insertMany( [\n {\n \"_id\" : 1,\n \"grades\" : [\n { \"grade\" : 80, \"mean\" : 75, \"std\" : 8 },\n { \"grade\" : 85, \"mean\" : 90, \"std\" : 6 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 8 }\n ]\n },\n {\n \"_id\" : 2,\n \"grades\" : [\n { \"grade\" : 90, \"mean\" : 75, \"std\" : 8 },\n { \"grade\" : 87, \"mean\" : 90, \"std\" : 5 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 6 }\n ]\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students2</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">8</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">8</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">8</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To modify the value of the
<code class="leafygreen-ui-1l06pbn">
std
</code>
field for all elements in the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
array, use the positional
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.---" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
</span>
</a>
operator:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.updateMany(\n { },\n { $inc: { \"grades.$[].std\" : -2 } },\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students2</span>.<span class="lg-highlight-title lg-highlight-function">updateMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[].std"</span> <!-- -->: <!-- -->-<span class="lg-highlight-number">2</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
After the operation, the collection has the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"grades\" : [\n { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 85, \"mean\" : 90, \"std\" : 4 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 6 }\n ]\n}\n{\n \"_id\" : 2,\n \"grades\" : [\n { \"grade\" : 90, \"mean\" : 75, \"std\" : 6 },\n { \"grade\" : 87, \"mean\" : 90, \"std\" : 3 },\n { \"grade\" : 85, \"mean\" : 85, \"std\" : 4 }\n ]\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">75</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">6</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">87</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"mean"</span> <!-- -->: <span class="lg-highlight-number">85</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update Arrays Specified Using a Negation Query Operator
<a class="headerlink leafygreen-ui-1kepx47" href="#update-arrays-specified-using-a-negation-query-operator" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-arrays-specified-using-a-negation-query-operator">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create the
<code class="leafygreen-ui-1l06pbn">
results
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.results.insertMany( [\n { \"_id\" : 1, \"grades\" : [ 85, 82, 80 ] },\n { \"_id\" : 2, \"grades\" : [ 88, 90, 92 ] },\n { \"_id\" : 3, \"grades\" : [ 85, 100, 90 ] }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">results</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">85</span>, <span class="lg-highlight-number">82</span>, <span class="lg-highlight-number">80</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">88</span>, <span class="lg-highlight-number">90</span>, <span class="lg-highlight-number">92</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">85</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">90</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To increment all elements in the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
array by
<code class="leafygreen-ui-1l06pbn">
10
</code>
for all
documents
<strong>
except
</strong>
those with the value
<code class="leafygreen-ui-1l06pbn">
100
</code>
in the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
array, use the all positional
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.---" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
</span>
</a>
operator:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.results.updateMany(\n { \"grades\" : { $ne: 100 } },\n { $inc: { \"grades.$[]\": 10 } },\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">results</span>.<span class="lg-highlight-title lg-highlight-function">updateMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$ne</span>: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[]"</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The all positional
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-update-up.---" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
</span>
</a>
operator acts as a
placeholder for all elements in the array field.
</p>
<p class="leafygreen-ui-1kp3ins">
After the operation, the
<code class="leafygreen-ui-1l06pbn">
students
</code>
collection contains the following
documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"grades\" : [ 95, 92, 90 ] }\n{ \"_id\" : 2, \"grades\" : [ 98, 100, 102 ] }\n{ \"_id\" : 3, \"grades\" : [ 85, 100, 90 ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">92</span>, <span class="lg-highlight-number">90</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">98</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">102</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">85</span>, <span class="lg-highlight-number">100</span>, <span class="lg-highlight-number">90</span> ] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-position-nested-arrays">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update Nested Arrays in Conjunction with
<code class="leafygreen-ui-1l06pbn">
$[<identifier>]
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#update-nested-arrays-in-conjunction-with----identifier--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-nested-arrays-in-conjunction-with----identifier--">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
$[]
</code>
positional operator, in conjunction with filter
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/positional-filtered/#mongodb-update-up.---identifier--">
<code class="leafygreen-ui-1l06pbn">
$[<identifier>]
</code>
</a>
positional operator can be used to update nested
arrays.
</p>
<p class="leafygreen-ui-1kp3ins">
Create a collection
<code class="leafygreen-ui-1l06pbn">
students3
</code>
with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students3.insertMany( [\n { \"_id\" : 1,\n \"grades\" : [\n { type: \"quiz\", questions: [ 10, 8, 5 ] },\n { type: \"quiz\", questions: [ 8, 9, 6 ] },\n { type: \"hw\", questions: [ 5, 4, 3 ] },\n { type: \"exam\", questions: [ 25, 10, 23, 0 ] },\n ]\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students3</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"quiz"</span>, <span class="lg-highlight-attr">questions</span>: <!-- -->[ <span class="lg-highlight-number">10</span>, <span class="lg-highlight-number">8</span>, <span class="lg-highlight-number">5</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"quiz"</span>, <span class="lg-highlight-attr">questions</span>: <!-- -->[ <span class="lg-highlight-number">8</span>, <span class="lg-highlight-number">9</span>, <span class="lg-highlight-number">6</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"hw"</span>, <span class="lg-highlight-attr">questions</span>: <!-- -->[ <span class="lg-highlight-number">5</span>, <span class="lg-highlight-number">4</span>, <span class="lg-highlight-number">3</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"exam"</span>, <span class="lg-highlight-attr">questions</span>: <!-- -->[ <span class="lg-highlight-number">25</span>, <span class="lg-highlight-number">10</span>, <span class="lg-highlight-number">23</span>, <span class="lg-highlight-number">0</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To update all values that are greater than or equal to
<code class="leafygreen-ui-1l06pbn">
8
</code>
in the
nested
<code class="leafygreen-ui-1l06pbn">
grades.questions
</code>
array, regardless of
<code class="leafygreen-ui-1l06pbn">
type
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students3.updateMany(\n {},\n { $inc: { \"grades.$[].questions.$[score]\": 2 } },\n { arrayFilters: [ { \"score\": { $gte: 8 } } ] }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">students3</span>.<span class="lg-highlight-title lg-highlight-function">updateMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[].questions.$[score]"</span>: <span class="lg-highlight-number">2</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">arrayFilters</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"score"</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">8</span> } } ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The updated documents look like this:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: 1,\n grades: [\n { type: 'quiz', questions: [ 12, 10, 5 ] },\n { type: 'quiz', questions: [ 10, 11, 6 ] },\n { type: 'hw', questions: [ 5, 4, 3 ] },\n { type: 'exam', questions: [ 27, 12, 25, 0 ] }\n ]\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">grades</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'quiz'</span>, <span class="lg-highlight-attr">questions</span>: <!-- -->[ <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">10</span>, <span class="lg-highlight-number">5</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'quiz'</span>, <span class="lg-highlight-attr">questions</span>: <!-- -->[ <span class="lg-highlight-number">10</span>, <span class="lg-highlight-number">11</span>, <span class="lg-highlight-number">6</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'hw'</span>, <span class="lg-highlight-attr">questions</span>: <!-- -->[ <span class="lg-highlight-number">5</span>, <span class="lg-highlight-number">4</span>, <span class="lg-highlight-number">3</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'exam'</span>, <span class="lg-highlight-attr">questions</span>: <!-- -->[ <span class="lg-highlight-number">27</span>, <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">25</span>, <span class="lg-highlight-number">0</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/positional-filtered/#mongodb-update-up.---identifier--">
<code class="leafygreen-ui-1l06pbn">
$[<identifier>]
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#mongodb-method-db.collection.updateMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateMany()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify">
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/elemMatch/#mongodb-query-op.-elemMatch">
<code class="leafygreen-ui-1l06pbn">
$elemMatch
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/data-modeling/concepts/embedding-vs-references/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Embedded Data Versus References
<a class="headerlink leafygreen-ui-1kepx47" href="#embedded-data-versus-references" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="embedded-data-versus-references">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#embedded-data-models" target="_self">
<span>
Embedded Data Models
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#use-cases" target="_self">
<span>
Use Cases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#query-embedded-data" target="_self">
<span>
Query Embedded Data
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#references" target="_self">
<span>
References
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#use-cases-1" target="_self">
<span>
Use Cases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#query-normalized-data-models" target="_self">
<span>
Query Normalized Data Models
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Effective data models support your application's needs. One key decision
for your schema design is whether to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-data-modeling-embedding" target="_self">
<span>
embed data
</span>
</a>
or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-data-modeling-referencing" target="_self">
<span>
use references
<!-- -->
.
</span>
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-data-modeling-embedding">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Embedded Data Models
<a class="headerlink leafygreen-ui-1kepx47" href="#embedded-data-models" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="embedded-data-models">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can embed related data in a single document. In the following
example, the
<code class="leafygreen-ui-1l06pbn">
contact
</code>
and
<code class="leafygreen-ui-1l06pbn">
access
</code>
fields are embedded documents:
</p>
<div class="figure css-5vkxs0" style="width:720px">
<img alt="Data model with embedded fields that contain all related information." class="leafygreen-ui-1qnf57e" height="350" src="/docs/manual/images/data-model-denormalized.bakedsvg.svg" style="--border-color:#C1C7C6" width="620"/>
</div>
<p class="leafygreen-ui-1kp3ins">
Embedded data models are often
<strong>
denormalized
</strong>
, because
frequently-accessed data is duplicated in multiple collections.
</p>
<p class="leafygreen-ui-1kp3ins">
Embedded data models let applications query related pieces of
information in the same database record. As a result, applications
require fewer queries and updates to complete common operations.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use Cases
<a class="headerlink leafygreen-ui-1kepx47" href="#use-cases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-cases">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Use embedded data models in the following scenarios:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You have "contains" relationships between entities. For example, a
<code class="leafygreen-ui-1l06pbn">
contacts
</code>
document that contains an
<code class="leafygreen-ui-1l06pbn">
address
</code>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-one-relationships-between-documents/#std-label-data-modeling-example-one-to-one">
Model One-to-One Relationships with Embedded Documents
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You have one-to-many relationships between entities. In these
relationships, the "many" or child documents are viewed in the context
of the "one" or parent documents. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/#std-label-data-modeling-example-one-to-many">
Model One-to-Many Relationships with Embedded Documents
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Embedding provides the following benefits:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Better performance for read operations
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The ability to retrieve related data in a single database operation
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The ability to to update related data in a single atomic write
operation
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query Embedded Data
<a class="headerlink leafygreen-ui-1kepx47" href="#query-embedded-data" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="query-embedded-data">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To query data within embedded documents, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-dot-notation">
dot notation
</a>
. For
examples of querying data in arrays and embedded documents, see:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/query-arrays/#std-label-read-operations-arrays">
Query an Array
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/query-embedded-documents/#std-label-read-operations-embedded-documents">
Query on Embedded/Nested Documents
</a>
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Document Size Limit
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Documents in MongoDB must be smaller than 16 megabytes.
</p>
<p class="leafygreen-ui-1kp3ins">
For large binary data, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/gridfs/#std-label-gridfs">
GridFS
<!-- -->
.
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-data-modeling-referencing">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
References
<a class="headerlink leafygreen-ui-1kepx47" href="#references" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="references">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
References store relationships between data by including links, called
<strong>
references
</strong>
, from one document to another. In the following example,
the
<code class="leafygreen-ui-1l06pbn">
contact
</code>
and
<code class="leafygreen-ui-1l06pbn">
access
</code>
documents contain a reference to the
<code class="leafygreen-ui-1l06pbn">
user
</code>
document.
</p>
<div class="figure css-5vkxs0" style="width:720px">
<img alt="Data model using references to link documents. Both the ``contact`` document and the ``access`` document contain a reference to the ``user`` document." class="leafygreen-ui-1qnf57e" height="450" src="/docs/manual/images/data-model-normalized.bakedsvg.svg" style="--border-color:#C1C7C6" width="740"/>
</div>
<p class="leafygreen-ui-1kp3ins">
References result in
<strong>
normalized
</strong>
data models because data is divided
into multiple collections and not duplicated.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use Cases
<a class="headerlink leafygreen-ui-1kepx47" href="#use-cases-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-cases-1">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Use references to link related data in the following scenarios:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Embedding would result in duplication of data but would not
provide sufficient read performance advantages to outweigh the
implications of the duplication. For example, when the embedded data
frequently changes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You need to represent complex many-to-many relationships or large
hierarchical data sets.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The related entity is frequently queried on its own. For example, if
you have
<code class="leafygreen-ui-1l06pbn">
employee
</code>
and
<code class="leafygreen-ui-1l06pbn">
department
</code>
data, you may consider
embedding department information in the
<code class="leafygreen-ui-1l06pbn">
employee
</code>
documents.
However, if you often query for a list of departments, your
application will perform best with a separate
<code class="leafygreen-ui-1l06pbn">
department
</code>
collection that is linked to the
<code class="leafygreen-ui-1l06pbn">
employee
</code>
collection with a
reference.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query Normalized Data Models
<a class="headerlink leafygreen-ui-1kepx47" href="#query-normalized-data-models" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="query-normalized-data-models">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To query normalized data in multiple collections, MongoDB provides the
following aggregation stages:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup">
<code class="leafygreen-ui-1l06pbn">
$lookup
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/graphLookup/#mongodb-pipeline-pipe.-graphLookup">
<code class="leafygreen-ui-1l06pbn">
$graphLookup
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For an example of normalized data models, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/#std-label-data-modeling-publisher-and-books">
Model One-to-Many Relationships with Document References
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For examples of various tree models, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/applications/data-models-tree-structures/#std-label-data-model-tree-structure">
Model Tree Structures
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For more information on data modeling with MongoDB, download the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/modernize?tck=docs_server" target="_self">
<span>
MongoDB Application Modernization Guide
</span>
</a>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The download includes the following resources:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Presentation on the methodology of data modeling with MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
White paper covering best practices and considerations for
migrating to MongoDB from an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-RDBMS">
RDBMS
</a>
data model
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Reference MongoDB schema with its RDBMS equivalent
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Application Modernization scorecard
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model One-to-Many Relationships with Embedded Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#model-one-to-many-relationships-with-embedded-documents" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-one-to-many-relationships-with-embedded-documents">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#embedded-document-pattern" target="_self">
<span>
Embedded Document Pattern
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a data model that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
embedded
</a>
documents to describe a one-to-many
relationship between connected data. Embedding connected data
in a single document can reduce the number of read operations required
to obtain data. In general, structure your schema so your application receives
all of its required information in a single read operation. For example, you
can use the the embedded one-to-many model to describe the following relationships:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Country to major cities
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Author to books
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Student to classes
</p>
</li>
</ul>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The example schema contains three entities, with
<code class="leafygreen-ui-1l06pbn">
address one
</code>
and
<code class="leafygreen-ui-1l06pbn">
address two
</code>
belonging to the same
<code class="leafygreen-ui-1l06pbn">
patron
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// patron document\n{\n _id: \"joe\",\n name: \"Joe Bookreader\"\n}\n\n// address one\n{\n street: \"123 Fake Street\",\n city: \"Faketon\",\n state: \"MA\",\n zip: \"12345\"\n}\n\n// address two\n{\n street: \"1 Some Other Street\",\n city: \"Boston\",\n state: \"MA\",\n zip: \"12345\"\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// patron document</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"joe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Joe Bookreader"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// address one</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">street</span>: <span class="lg-highlight-string">"123 Fake Street"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">"Faketon"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"MA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-string">"12345"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// address two</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">street</span>: <span class="lg-highlight-string">"1 Some Other Street"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">"Boston"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"MA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-string">"12345"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-one-to-many-embedded-document-pattern">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Embedded Document Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#embedded-document-pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="embedded-document-pattern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
In this example the application needs to display information for the
<code class="leafygreen-ui-1l06pbn">
patron
</code>
and both
<code class="leafygreen-ui-1l06pbn">
address
</code>
objects on a single page. To allow your application to
retrieve all necessary information with a single query, embed the
<code class="leafygreen-ui-1l06pbn">
address one
</code>
and
<code class="leafygreen-ui-1l06pbn">
address two
</code>
information inside of the
<code class="leafygreen-ui-1l06pbn">
patron
</code>
document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": \"joe\",\n \"name\": \"Joe Bookreader\",\n \"addresses\": [\n {\n \"street\": \"123 Fake Street\",\n \"city\": \"Faketon\",\n \"state\": \"MA\",\n \"zip\": \"12345\"\n },\n {\n \"street\": \"1 Some Other Street\",\n \"city\": \"Boston\",\n \"state\": \"MA\",\n \"zip\": \"12345\"\n }\n ]\n }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span>: <span class="lg-highlight-string">"joe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span>: <span class="lg-highlight-string">"Joe Bookreader"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"addresses"</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"street"</span>: <span class="lg-highlight-string">"123 Fake Street"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"city"</span>: <span class="lg-highlight-string">"Faketon"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span>: <span class="lg-highlight-string">"MA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"zip"</span>: <span class="lg-highlight-string">"12345"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"street"</span>: <span class="lg-highlight-string">"1 Some Other Street"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"city"</span>: <span class="lg-highlight-string">"Boston"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span>: <span class="lg-highlight-string">"MA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"zip"</span>: <span class="lg-highlight-string">"12345"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-one-relationships-between-documents/#std-label-data-modeling-example-one-to-one">
Model One-to-One Relationships with Embedded Documents
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/#std-label-data-modeling-publisher-and-books">
Model One-to-Many Relationships with Document References
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/applications/data-models-relationships/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Document Relationships
<a class="headerlink leafygreen-ui-1kepx47" href="#document-relationships" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="document-relationships">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#get-started" target="_self">
<span>
Get Started
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB's flexible data model gives you multiple options to map
relationships between different entities in your schema.
</p>
<p class="leafygreen-ui-1kp3ins">
Generally, your choice of data model depends on whether you want to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
embed related data
</a>
in the same
collection or use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-referencing">
references
</a>
to
connect related data that exists in separate collections. Before you
choose a relationship pattern, review
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-embedding-vs-references">
Embedded Data Versus References
</a>
to
understand the advantages of each approach.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Get Started
<a class="headerlink leafygreen-ui-1kepx47" href="#get-started" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="get-started">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
These pages show examples of different data relationships and how to
apply them in a MongoDB schema:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-one-relationships-between-documents/#std-label-data-modeling-example-one-to-one">
Model One-to-One Relationships with Embedded Documents
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/#std-label-data-modeling-example-one-to-many">
Model One-to-Many Relationships with Embedded Documents
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/#std-label-data-modeling-publisher-and-books">
Model One-to-Many Relationships with Document References
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-many-to-many-relationships-between-documents/#std-label-data-modeling-example-many-to-many">
Model Many-to-Many Relationships with Embedded Documents
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model One-to-Many Relationships with Document References
<a class="headerlink leafygreen-ui-1kepx47" href="#model-one-to-many-relationships-with-document-references" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-one-to-many-relationships-with-document-references">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#pattern" target="_self">
<span>
Pattern
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This page describes a data model that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-referencing">
references
</a>
between documents to describe one-to-many
relationships between connected data.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="pattern">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider the following example that maps publisher and book
relationships. The example illustrates the advantage of referencing
over embedding to avoid repetition of the publisher information.
</p>
<p class="leafygreen-ui-1kp3ins">
Embedding the publisher document inside the book document would lead to
<strong>
repetition
</strong>
of the publisher data, as the following documents show:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n title: \"MongoDB: The Definitive Guide\",\n author: [ \"Kristina Chodorow\", \"Mike Dirolf\" ],\n published_date: ISODate(\"2010-09-24\"),\n pages: 216,\n language: \"English\",\n publisher: {\n name: \"O'Reilly Media\",\n founded: 1980,\n location: \"CA\"\n }\n}\n\n{\n title: \"50 Tips and Tricks for MongoDB Developer\",\n author: \"Kristina Chodorow\",\n published_date: ISODate(\"2011-05-06\"),\n pages: 68,\n language: \"English\",\n publisher: {\n name: \"O'Reilly Media\",\n founded: 1980,\n location: \"CA\"\n }\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"MongoDB: The Definitive Guide"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->[ <span class="lg-highlight-string">"Kristina Chodorow"</span>, <span class="lg-highlight-string">"Mike Dirolf"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">published_date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2010-09-24"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pages</span>: <span class="lg-highlight-number">216</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">language</span>: <span class="lg-highlight-string">"English"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">publisher</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"O'Reilly Media"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">founded</span>: <span class="lg-highlight-number">1980</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">"CA"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"50 Tips and Tricks for MongoDB Developer"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <span class="lg-highlight-string">"Kristina Chodorow"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">published_date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-05-06"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pages</span>: <span class="lg-highlight-number">68</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">language</span>: <span class="lg-highlight-string">"English"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">publisher</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"O'Reilly Media"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">founded</span>: <span class="lg-highlight-number">1980</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">"CA"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To avoid repetition of the publisher data, use
<em>
references
</em>
and keep
the publisher information in a separate collection from the book
collection.
</p>
<p class="leafygreen-ui-1kp3ins">
When using references, the growth of the relationships determine where
to store the reference. If the number of books per publisher is small
with limited growth, storing the book reference inside the publisher
document may sometimes be useful. Otherwise, if the number of books per
publisher is unbounded, this data model would lead to mutable, growing
arrays, as in the following example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n name: \"O'Reilly Media\",\n founded: 1980,\n location: \"CA\",\n books: [123456789, 234567890, ...]\n}\n\n{\n _id: 123456789,\n title: \"MongoDB: The Definitive Guide\",\n author: [ \"Kristina Chodorow\", \"Mike Dirolf\" ],\n published_date: ISODate(\"2010-09-24\"),\n pages: 216,\n language: \"English\"\n}\n\n{\n _id: 234567890,\n title: \"50 Tips and Tricks for MongoDB Developer\",\n author: \"Kristina Chodorow\",\n published_date: ISODate(\"2011-05-06\"),\n pages: 68,\n language: \"English\"\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"O'Reilly Media"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">founded</span>: <span class="lg-highlight-number">1980</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">"CA"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">books</span>: <!-- -->[<span class="lg-highlight-number">123456789</span>, <span class="lg-highlight-number">234567890</span>, <!-- -->...<!-- -->]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">123456789</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"MongoDB: The Definitive Guide"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->[ <span class="lg-highlight-string">"Kristina Chodorow"</span>, <span class="lg-highlight-string">"Mike Dirolf"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">published_date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2010-09-24"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pages</span>: <span class="lg-highlight-number">216</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">language</span>: <span class="lg-highlight-string">"English"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">234567890</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"50 Tips and Tricks for MongoDB Developer"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <span class="lg-highlight-string">"Kristina Chodorow"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">published_date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-05-06"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pages</span>: <span class="lg-highlight-number">68</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">language</span>: <span class="lg-highlight-string">"English"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To avoid mutable, growing arrays, store the publisher reference inside
the book document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: \"oreilly\",\n name: \"O'Reilly Media\",\n founded: 1980,\n location: \"CA\"\n}\n\n{\n _id: 123456789,\n title: \"MongoDB: The Definitive Guide\",\n author: [ \"Kristina Chodorow\", \"Mike Dirolf\" ],\n published_date: ISODate(\"2010-09-24\"),\n pages: 216,\n language: \"English\",\n publisher_id: \"oreilly\"\n}\n\n{\n _id: 234567890,\n title: \"50 Tips and Tricks for MongoDB Developer\",\n author: \"Kristina Chodorow\",\n published_date: ISODate(\"2011-05-06\"),\n pages: 68,\n language: \"English\",\n publisher_id: \"oreilly\"\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"oreilly"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"O'Reilly Media"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">founded</span>: <span class="lg-highlight-number">1980</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">"CA"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">123456789</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"MongoDB: The Definitive Guide"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->[ <span class="lg-highlight-string">"Kristina Chodorow"</span>, <span class="lg-highlight-string">"Mike Dirolf"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">published_date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2010-09-24"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pages</span>: <span class="lg-highlight-number">216</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">language</span>: <span class="lg-highlight-string">"English"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">publisher_id</span>: <span class="lg-highlight-string">"oreilly"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">234567890</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"50 Tips and Tricks for MongoDB Developer"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <span class="lg-highlight-string">"Kristina Chodorow"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">published_date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-05-06"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pages</span>: <span class="lg-highlight-number">68</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">language</span>: <span class="lg-highlight-string">"English"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">publisher_id</span>: <span class="lg-highlight-string">"oreilly"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-embedded-many-to-many-relationships-between-documents/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Many-to-Many Relationships with Embedded Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#model-many-to-many-relationships-with-embedded-documents" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-many-to-many-relationships-with-embedded-documents">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#about-this-task" target="_self">
<span>
About this Task
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#embedded-document-pattern" target="_self">
<span>
Embedded Document Pattern
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a data model that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
embedded
</a>
documents to describe a many-to-many relationship
between connected data. Embedding connected data in a single document can
reduce the number of read operations required to obtain data. In general,
structure your schema so your application receives all of its required
information in a single read operation. For example, you can use the embedded
many-to-many model to describe the following relationships:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Students to classes
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Actors to movies
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Doctors to patients
</p>
</li>
</ul>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
About this Task
<a class="headerlink leafygreen-ui-1kepx47" href="#about-this-task" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="about-this-task">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following example schema contains information regarding
<code class="leafygreen-ui-1l06pbn">
book one
</code>
and
<code class="leafygreen-ui-1l06pbn">
book two
</code>
and their authors. You can represent the relationship
differently based on whether you anticipate application users querying by
book or by author.
</p>
<p class="leafygreen-ui-1kp3ins">
If you expect more users to query by book than by author, the example schema
is an effective choice. However, if you expect more queries by author, make
the author the top-level information and place the author's books in an embedded
field.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can use a many-to-many relationship to describe books and authors. A book
can have multiple authors, and an author can write multiple books.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Embedded Document Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#embedded-document-pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="embedded-document-pattern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The application needs to display information for the book and author
objects on a single page. To allow your application to retrieve all
necessary information with a single query, embed author information
inside of the corresponding book document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: \"book001\",\n title: \"Cell Biology\",\n authors: [\n {\n author_id: \"author124\",\n name: \"Ellie Smith\"\n },\n {\n author_id: \"author381\",\n name: \"John Palmer\"\n }\n ]\n}\n\n{\n _id: \"book002\",\n title: \"Organic Chemistry\",\n authors: [\n {\n author_id: \"author290\",\n name: \"Jane James\"\n },\n {\n author_id: \"author381\",\n name: \"John Palmer\"\n }\n ]\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"book001"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"Cell Biology"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">authors</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author_id</span>: <span class="lg-highlight-string">"author124"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Ellie Smith"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author_id</span>: <span class="lg-highlight-string">"author381"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"John Palmer"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"book002"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"Organic Chemistry"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">authors</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author_id</span>: <span class="lg-highlight-string">"author290"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Jane James"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author_id</span>: <span class="lg-highlight-string">"author381"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"John Palmer"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-one-relationships-between-documents/#std-label-data-modeling-example-one-to-one">
Model One-to-One Relationships with Embedded Documents
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/#std-label-data-modeling-example-one-to-many">
Model One-to-Many Relationships with Embedded Documents
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/views/drop-view/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Remove a View
<a class="headerlink leafygreen-ui-1kepx47" href="#remove-a-view" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="remove-a-view">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
To remove a view, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.drop/#mongodb-method-db.collection.drop">
<code class="leafygreen-ui-1l06pbn">
db.collection.drop()
</code>
</a>
method on the
view.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, this command drops a view named
<code class="leafygreen-ui-1l06pbn">
productView01
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.productView01.drop()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">productView01</span>.<span class="lg-highlight-title lg-highlight-function">drop</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-embedded-one-to-one-relationships-between-documents/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model One-to-One Relationships with Embedded Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#model-one-to-one-relationships-with-embedded-documents" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-one-to-one-relationships-with-embedded-documents">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#embedded-document-pattern" target="_self">
<span>
Embedded Document Pattern
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a data model that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
embedded
</a>
documents to describe a one-to-one
relationship between connected data. Embedding connected data
in a single document can reduce the number of read operations required
to obtain data. In general, structure your schema so your application receives
all of its required information in a single read operation. For example, you
can use the the embedded one-to-one model to describe the following relationships:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Country to capital city
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
User account to email address
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Building to address
</p>
</li>
</ul>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The example schema contains two entities, a
<code class="leafygreen-ui-1l06pbn">
patron
</code>
and an
<code class="leafygreen-ui-1l06pbn">
address
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// patron document\n{\n _id: \"joe\",\n name: \"Joe Bookreader\"\n}\n// address document\n{\n street: \"123 Fake Street\",\n city: \"Faketon\",\n state: \"MA\",\n zip: \"12345\"\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// patron document</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"joe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Joe Bookreader"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// address document</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">street</span>: <span class="lg-highlight-string">"123 Fake Street"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">"Faketon"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"MA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-string">"12345"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-one-to-one-embedded-document-pattern">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Embedded Document Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#embedded-document-pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="embedded-document-pattern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
address
</code>
data is frequently retrieved with the
<code class="leafygreen-ui-1l06pbn">
patron
</code>
information. To allow
your application to retreive all necessary information with a single query, embed the
<code class="leafygreen-ui-1l06pbn">
address
</code>
information inside of the
<code class="leafygreen-ui-1l06pbn">
patron
</code>
document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: \"joe\",\n name: \"Joe Bookreader\",\n address: {\n street: \"123 Fake Street\",\n city: \"Faketon\",\n state: \"MA\",\n zip: \"12345\"\n }\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"joe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Joe Bookreader"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">address</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">street</span>: <span class="lg-highlight-string">"123 Fake Street"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">city</span>: <span class="lg-highlight-string">"Faketon"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"MA"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-string">"12345"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/#std-label-data-modeling-example-one-to-many">
Model One-to-Many Relationships with Embedded Documents
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/#std-label-data-modeling-publisher-and-books">
Model One-to-Many Relationships with Document References
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/release-notes/7.0-upgrade-standalone/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Upgrade a Standalone to 7.0
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-a-standalone-to-7.0" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-a-standalone-to-7.0">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#upgrade-recommendations-and-checklists" target="_self">
<span>
Upgrade Recommendations and Checklists
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#prerequisites" target="_self">
<span>
Prerequisites
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#download-newversion-binaries" target="_self">
<span>
Download
<!-- -->
7.0
<!-- -->
Binaries
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#upgrade-procedure" target="_self">
<span>
Upgrade Procedure
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-upgrade-procedures" target="_self">
<span>
Additional Upgrade Procedures
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Use this tutorial to upgrade from MongoDB
<!-- -->
6.0
<!-- -->
to MongoDB
<!-- -->
7.0
<!-- -->
. To upgrade to a new patch release within the same release
series, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/upgrade-revision/#std-label-upgrade-to-latest-revision">
Upgrade to the Latest Self-Managed Patch Release of MongoDB
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Familiarize yourself with the content of this document, including
thoroughly reviewing the prerequisites, prior to upgrading to MongoDB
<!-- -->
7.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
The following steps outline the procedure to upgrade a standalone
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
from version
<!-- -->
6.0
<!-- -->
to
<!-- -->
7.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
If you need guidance on upgrading to
<!-- -->
7.0
<!-- -->
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/products/consulting?tck=docs_server" target="_self">
<span>
MongoDB
professional services
</span>
</a>
offer major version upgrade support to help ensure a smooth transition
without interruption to your MongoDB application.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Upgrade Recommendations and Checklists
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-recommendations-and-checklists" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-recommendations-and-checklists">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When upgrading, consider the following:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Upgrade Version Path
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-version-path" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-version-path">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To upgrade an existing MongoDB deployment to
<!-- -->
7.0
<!-- -->
, you must be
running a
<!-- -->
6.0-series
<!-- -->
release.
</p>
<p class="leafygreen-ui-1kp3ins">
To upgrade from a version earlier than the
<!-- -->
6.0-series
<!-- -->
, you must
successively upgrade major releases until you have upgraded to
<!-- -->
6.0-series
<!-- -->
. For example, if you are running a
<!-- -->
5.0-series
<!-- -->
, you must
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0/#std-label-6.0-upgrade">
upgrade first to 6.0
</a>
<em>
before
</em>
you can upgrade to
<!-- -->
7.0
<!-- -->
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Check Driver Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#check-driver-compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="check-driver-compatibility">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Before you upgrade MongoDB, check that you're using a MongoDB
<!-- -->
7.0
<!-- -->
-compatible driver. Consult the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver documentation
</span>
</a>
for your specific driver to verify
compatibility with MongoDB
<!-- -->
7.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
Upgraded deployments that run on incompatible drivers might encounter
unexpected or undefined behavior.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Preparedness
<a class="headerlink leafygreen-ui-1kepx47" href="#preparedness" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="preparedness">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Before beginning your upgrade, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-compatibility/#std-label-7.0-compatibility">
Compatibility Changes in MongoDB 7.0
</a>
document to
ensure that your applications and deployments are compatible with
MongoDB
<!-- -->
7.0
<!-- -->
. Resolve the incompatibilities in your deployment
before starting the upgrade.
</p>
<p class="leafygreen-ui-1kp3ins">
Before upgrading MongoDB, always test your application in a staging
environment before deploying the upgrade to your production
environment.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Downgrade Consideration
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-consideration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="downgrade-consideration">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You cannot downgrade your deployment's binary version without assistance from
support.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/8.0-downgrade/#std-label-8.0-downgrade">
Downgrade
<!-- -->
8.0
<!-- -->
to
<!-- -->
7.0
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Prerequisites
<a class="headerlink leafygreen-ui-1kepx47" href="#prerequisites" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="prerequisites">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Feature Compatibility Version
<a class="headerlink leafygreen-ui-1kepx47" href="#feature-compatibility-version" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="feature-compatibility-version">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
6.0
<!-- -->
instance must have
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
set
to
<code class="leafygreen-ui-1l06pbn">
"6.0"
</code>
. To check
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">getParameter</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">featureCompatibilityVersion</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns a document with the current feature compatibility
version:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ featureCompatibilityVersion : { version : \"6.0\" }, ok: 1}","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <!-- -->featureCompatibilityVersion <!-- -->: <!-- -->{ <!-- -->version <!-- -->: <span class="lg-highlight-string">"6.0"</span> }<!-- -->, <span class="lg-highlight-attr">ok</span>: <span class="lg-highlight-number">1</span>}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To set or update
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
to
<code class="leafygreen-ui-1l06pbn">
6.0
</code>
, run the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { setFeatureCompatibilityVersion: \"6.0\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">setFeatureCompatibilityVersion</span>: <span class="lg-highlight-string">"6.0"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Consider Converting to Replica Set
<a class="headerlink leafygreen-ui-1kepx47" href="#consider-converting-to-replica-set" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="consider-converting-to-replica-set">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Prior to upgrading, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/convert-standalone-to-replica-set/#std-label-server-replica-set-deploy-convert">
converting your standalone deployment to a replica set
</a>
. Replica sets are the
recommended deployment configuration for MongoDB.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Download
<!-- -->
7.0
<!-- -->
Binaries
<a class="headerlink leafygreen-ui-1kepx47" href="#download-newversion-binaries" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-newversion-binaries">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Via Package Manager
<a class="headerlink leafygreen-ui-1kepx47" href="#via-package-manager" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="via-package-manager">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you installed MongoDB from the MongoDB
<code class="leafygreen-ui-1l06pbn">
apt
</code>
,
<code class="leafygreen-ui-1l06pbn">
yum
</code>
,
<code class="leafygreen-ui-1l06pbn">
dnf
</code>
, or
<code class="leafygreen-ui-1l06pbn">
zypper
</code>
repositories, you should upgrade to
<!-- -->
7.0
<!-- -->
using your package
manager.
</p>
<p class="leafygreen-ui-1kp3ins">
Follow the appropriate
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
7.0 installation instructions
</a>
for your Linux system. This
will involve adding a repository for the new release, then performing
the actual upgrade process.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Manually
<a class="headerlink leafygreen-ui-1kepx47" href="#manually" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="manually">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you have not installed MongoDB using a package manager, you can
manually download the MongoDB binaries from the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/try/download?tck=docs_server" target="_self">
<span>
MongoDB Download
Center
</span>
</a>
.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
7.0 installation instructions
</a>
for more information.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Upgrade Procedure
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-procedure" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-procedure">
</div>
</a>
</h2>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"To shut down the mongod process, use\nmongosh to connect to the instance and run the\nfollowing command:","name":"Shut down the mongod instance."},{"@type":"HowToStep","text":"Ensure that the 7.0-series binaries are in your System PATH. To\nconfirm your binary version, run the following command:The command output indicates a 7.0-series release.","name":"Replace the 6.0 binaries with the 7.0 binaries."},{"@type":"HowToStep","text":"At this point, you can run the 7.0 binaries without the\n7.0 features that are incompatible with 6.0.To enable these 7.0 features, set the feature compatibility\nversion (fCV) to 7.0.Enabling these backwards-incompatible features can complicate the\ndowngrade process since you must remove any persisted backwards-incompatible\nfeatures before you downgrade.It is recommended that after upgrading, you allow your deployment to run\nwithout enabling these features for a burn-in period to ensure the\nlikelihood of downgrade is minimal. When you are confident that the\nlikelihood of downgrade is minimal, enable these features.Run the setFeatureCompatibilityVersion command\nagainst the admin database:This command must perform writes to an internal system\ncollection. If for any reason the command does not complete\nsuccessfully, you can safely retry the command as the operation\nis idempotent.","name":"Enable backwards-incompatible 7.0 features."}],"name":"Upgrade Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Shut down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance.
<a class="headerlink leafygreen-ui-1kepx47" href="#shut-down-the--instance." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shut-down-the--instance.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To shut down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to connect to the instance and run the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { shutdown: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">shutdown</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replace the
<!-- -->
6.0
<!-- -->
binaries with the
<!-- -->
7.0
<!-- -->
binaries.
<a class="headerlink leafygreen-ui-1kepx47" href="#replace-the--binaries-with-the--binaries." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replace-the--binaries-with-the--binaries.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Ensure that the
<!-- -->
7.0-series
<!-- -->
binaries are in your System PATH. To
confirm your binary version, run the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --version","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --version</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The command output indicates a
<!-- -->
7.0-series
<!-- -->
release.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Enable backwards-incompatible
<!-- -->
7.0
<!-- -->
features.
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-backwards-incompatible--features." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enable-backwards-incompatible--features.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
At this point, you can run the
<!-- -->
7.0
<!-- -->
binaries without the
<!-- -->
7.0
<!-- -->
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0/#std-label-7.0-downgrade-considerations">
features
</a>
that are incompatible with
<!-- -->
6.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
To enable these
<!-- -->
7.0
<!-- -->
features, set the feature compatibility
version (
<code class="leafygreen-ui-1l06pbn">
fCV
</code>
) to
<!-- -->
7.0
<!-- -->
.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Enabling these backwards-incompatible features can complicate the
downgrade process since you must remove any persisted backwards-incompatible
features before you downgrade.
</p>
<p class="leafygreen-ui-1kp3ins">
It is recommended that after upgrading, you allow your deployment to run
without enabling these features for a burn-in period to ensure the
likelihood of downgrade is minimal. When you are confident that the
likelihood of downgrade is minimal, enable these features.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
command
against the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { setFeatureCompatibilityVersion: \"7.0\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">setFeatureCompatibilityVersion</span>: <span class="lg-highlight-string">"7.0"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This command must perform writes to an internal system
collection. If for any reason the command does not complete
successfully, you can safely retry the command as the operation
is idempotent.
</p>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Upgrade Procedures
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-upgrade-procedures" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="additional-upgrade-procedures">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To upgrade a replica set, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-upgrade-replica-set/#std-label-7.0-upgrade-replica-set">
Upgrade a Replica Set to 7.0
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To upgrade a sharded cluster, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-upgrade-sharded-cluster/#std-label-7.0-upgrade-sharded-cluster">
Upgrade a Sharded Cluster to 7.0
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/rs.freeze/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
rs.freeze()
<a class="headerlink leafygreen-ui-1kepx47" href="#rs.freeze--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rs.freeze--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#description" target="_self">
<span>
Description
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Description
<a class="headerlink leafygreen-ui-1kepx47" href="#description" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="description">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
rs.freeze(seconds)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-rs.freeze" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-rs.freeze">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Makes the current
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
member ineligible to become
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
for the period specified.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for database commands or language-specific drivers,
such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For the database command, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetFreeze/#mongodb-dbcommand-dbcmd.replSetFreeze">
<code class="leafygreen-ui-1l06pbn">
replSetFreeze
</code>
</a>
command
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.freeze" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.freeze()
</code>
</span>
</a>
method has the following parameter:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Parameter
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
seconds
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
number
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The duration the member is ineligible to become primary.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/rs.conf/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
rs.conf()
<a class="headerlink leafygreen-ui-1kepx47" href="#rs.conf--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rs.conf--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output-example" target="_self">
<span>
Output Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
rs.conf()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-rs.conf" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-rs.conf">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns a document that contains the current
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
configuration.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for database commands or language-specific drivers,
such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For the database command, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetConfig/#mongodb-dbcommand-dbcmd.replSetGetConfig">
<code class="leafygreen-ui-1l06pbn">
replSetGetConfig
</code>
</a>
command
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetConfig/#mongodb-dbcommand-dbcmd.replSetGetConfig">
<code class="leafygreen-ui-1l06pbn">
replSetGetConfig
</code>
</a>
command
can specify a new option
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetConfig/#std-label-replSetGetConfig-commitmentStatus">
commitmentStatus: true
</a>
when run on the primary. When
run with the option, the command includes in the output a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetConfig/#std-label-replSetGetConfig-output-commitmentStatus">
commitmentStatus
</a>
field. This output field indicates whether the replica set's
previous reconfig has been committed, so that the replica set is
ready to be reconfigured again.
<!-- -->
The option is only available with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetConfig/#mongodb-dbcommand-dbcmd.replSetGetConfig">
<code class="leafygreen-ui-1l06pbn">
replSetGetConfig
</code>
</a>
command.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Output Example
<a class="headerlink leafygreen-ui-1kepx47" href="#output-example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="output-example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following document provides a representation of a replica set
configuration document. The configuration of your replica set may
include only a subset of these settings:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: <string>,\n version: <int>,\n term: <int>,\n protocolVersion: <number>,\n writeConcernMajorityJournalDefault: <boolean>,\n configsvr: <boolean>,\n members: [\n {\n _id: <int>,\n host: <string>,\n arbiterOnly: <boolean>,\n buildIndexes: <boolean>,\n hidden: <boolean>,\n priority: <number>,\n tags: <document>,\n secondaryDelaySecs: <int>,\n votes: <number>\n },\n ...\n ],\n settings: {\n chainingAllowed : <boolean>,\n heartbeatIntervalMillis : <int>,\n heartbeatTimeoutSecs: <int>,\n electionTimeoutMillis : <int>,\n catchUpTimeoutMillis : <int>,\n getLastErrorModes : <document>,\n getLastErrorDefaults : <document>,\n replicaSetId: <objectid>\n }\n}"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _id: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> version: <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> term: <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> protocolVersion: <number>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> writeConcernMajorityJournalDefault: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> configsvr: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> members: [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> _id: <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> host: <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> arbiterOnly: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> buildIndexes: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> hidden: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> priority: <number>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> tags: <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> secondaryDelaySecs: <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> votes: <number></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ],</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> settings: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> chainingAllowed : <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> heartbeatIntervalMillis : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> heartbeatTimeoutSecs: <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> electionTimeoutMillis : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> catchUpTimeoutMillis : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> getLastErrorModes : <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> getLastErrorDefaults : <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> replicaSetId: <ObjectId></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For description of the configuration settings, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/">
Self-Managed Replica Set Configuration
<!-- -->
.
</a>
</p>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
rs.config()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-rs.config" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-rs.config">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.config" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.config()
</code>
</span>
</a>
is an alias of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.conf" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.conf()
</code>
.
</span>
</a>
</p>
</dd>
</dl>
</section>
</section>
|
https://www.mongodb.com/docs/manual/applications/data-models/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Data Model Examples and Patterns
<a class="headerlink leafygreen-ui-1kepx47" href="#data-model-examples-and-patterns" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="data-model-examples-and-patterns">
</div>
</a>
</h1>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
For additional patterns and use cases, see also:
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/blog/post/building-with-patterns-a-summary" target="_self">
<span>
Building with
Patterns
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following documents provide overviews of various data modeling
patterns and common schema design considerations:
</p>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/applications/data-models-relationships/">
Document Relationships
</a>
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
Examples for modeling relationships between documents.
</p>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-one-relationships-between-documents/">
Model One-to-One Relationships with Embedded Documents
</a>
</dt>
<dd class="css-1ufxuu7">
Presents a data model that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
embedded documents
</a>
to describe one-to-one relationships
between connected data.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/">
Model One-to-Many Relationships with Embedded Documents
</a>
</dt>
<dd class="css-1ufxuu7">
Presents a data model that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
embedded documents
</a>
to describe one-to-many
relationships between connected data.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-embedded-many-to-many-relationships-between-documents/">
Model Many-to-Many Relationships with Embedded Documents
</a>
</dt>
<dd class="css-1ufxuu7">
Presents a data model that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
embedded documents
</a>
to describe many-to-many relationships
between connected data.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/">
Model One-to-Many Relationships with Document References
</a>
</dt>
<dd class="css-1ufxuu7">
Presents a data model that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-referencing">
references
</a>
to describe one-to-many
relationships between documents.
</dd>
</dl>
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/applications/data-models-tree-structures/">
Model Tree Structures
</a>
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
Examples for modeling tree structures.
</p>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-tree-structures-with-parent-references/">
Model Tree Structures with Parent References
</a>
</dt>
<dd class="css-1ufxuu7">
Presents a data model that organizes documents in a tree-like
structure by storing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-referencing">
references
</a>
to "parent" nodes in "child"
nodes.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-tree-structures-with-child-references/">
Model Tree Structures with Child References
</a>
</dt>
<dd class="css-1ufxuu7">
Presents a data model that organizes documents in a tree-like
structure by storing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-referencing">
references
</a>
to "child" nodes in "parent"
nodes.
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/applications/data-models-tree-structures/">
Model Tree Structures
</a>
for additional
examples of data models for tree structures.
</p>
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/applications/data-models-applications/">
Model Specific Application Contexts
</a>
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
Examples for models for specific application contexts.
</p>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-data-for-atomic-operations/">
Model Data for Atomic Operations
</a>
</dt>
<dd class="css-1ufxuu7">
Illustrates how embedding fields related to an atomic update
within the same document ensures that the fields are in sync.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-data-for-keyword-search/">
Model Data to Support Keyword Search
</a>
</dt>
<dd class="css-1ufxuu7">
Describes one method for supporting keyword search by storing
keywords in an array in the same document as the text field.
Combined with a multi-key index, this pattern can support
application's keyword search operations.
</dd>
</dl>
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-data-for-atomic-operations/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Data for Atomic Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#model-data-for-atomic-operations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-data-for-atomic-operations">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#pattern" target="_self">
<span>
Pattern
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Although MongoDB supports
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
multi-document transactions
</a>
for replica sets and sharded clusters, for many scenarios, the
denormalized data model, as discussed on this page, will continue to be optimal
for your data and use cases.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="pattern">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In MongoDB, a write operation on a single document is atomic. For
fields that must be updated together, embedding the fields within the
same document ensures that the fields can be updated atomically.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, consider a situation where you need to maintain
information on books, including the number of copies available for
checkout as well as the current checkout information.
</p>
<p class="leafygreen-ui-1kp3ins">
The available copies of the book and the checkout information should be
in sync. As such, embedding the
<code class="leafygreen-ui-1l06pbn">
available
</code>
field and the
<code class="leafygreen-ui-1l06pbn">
checkout
</code>
field within the same document ensures that you can update
the two fields atomically.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: 123456789,\n title: \"MongoDB: The Definitive Guide\",\n author: [ \"Kristina Chodorow\", \"Mike Dirolf\" ],\n published_date: ISODate(\"2010-09-24\"),\n pages: 216,\n language: \"English\",\n publisher_id: \"oreilly\",\n available: 3,\n checkout: [ { by: \"joe\", date: ISODate(\"2012-10-15\") } ]\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">123456789</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-string">"MongoDB: The Definitive Guide"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">author</span>: <!-- -->[ <span class="lg-highlight-string">"Kristina Chodorow"</span>, <span class="lg-highlight-string">"Mike Dirolf"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">published_date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2010-09-24"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pages</span>: <span class="lg-highlight-number">216</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">language</span>: <span class="lg-highlight-string">"English"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">publisher_id</span>: <span class="lg-highlight-string">"oreilly"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">available</span>: <span class="lg-highlight-number">3</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">checkout</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">by</span>: <span class="lg-highlight-string">"joe"</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-10-15"</span>) } ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Then to update with new checkout information, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
</a>
method to atomically update both
the
<code class="leafygreen-ui-1l06pbn">
available
</code>
field and the
<code class="leafygreen-ui-1l06pbn">
checkout
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.updateOne (\n { _id: 123456789, available: { $gt: 0 } },\n {\n $inc: { available: -1 },\n $push: { checkout: { by: \"abc\", date: new Date() } }\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">books</span>.<span class="lg-highlight-property">updateOne</span> <!-- -->(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">123456789</span>, <span class="lg-highlight-attr">available</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">0</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-attr">available</span>: <!-- -->-<span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$push</span>: <!-- -->{ <span class="lg-highlight-attr">checkout</span>: <!-- -->{ <span class="lg-highlight-attr">by</span>: <span class="lg-highlight-string">"abc"</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<!-- -->) } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns a document that contains information on the
status of the operation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"acknowledged\" : true, \"matchedCount\" : 1, \"modifiedCount\" : 1 }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"acknowledged"</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"matchedCount"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"modifiedCount"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
matchedCount
</code>
field shows that
<code class="leafygreen-ui-1l06pbn">
1
</code>
document matched the update
condition, and
<code class="leafygreen-ui-1l06pbn">
modifiedCount
</code>
shows that the operation updated
<code class="leafygreen-ui-1l06pbn">
1
</code>
document.
</p>
<p class="leafygreen-ui-1kp3ins">
If no document matched the update condition, then
<code class="leafygreen-ui-1l06pbn">
matchedCount
</code>
and
<code class="leafygreen-ui-1l06pbn">
modifiedCount
</code>
would be
<code class="leafygreen-ui-1l06pbn">
0
</code>
and would indicate that you could not
check out the book.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-monetary-data/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Monetary Data
<a class="headerlink leafygreen-ui-1kepx47" href="#model-monetary-data" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-monetary-data">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#numeric-model-1" target="_self">
<span>
Numeric Model
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#non-numeric-model-1" target="_self">
<span>
Non-Numeric Model
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Applications that handle monetary data often require the ability to
capture fractional units of currency and need to emulate decimal
rounding with exact precision when performing arithmetic.
The binary-based floating-point arithmetic used by many modern systems
(i.e., float, double) is unable to represent exact decimal fractions
and requires some degree of approximation making it unsuitable for
monetary arithmetic. This constraint is an important consideration when
modeling monetary data.
</p>
<p class="leafygreen-ui-1kp3ins">
There are several approaches to modeling monetary data in MongoDB using
the numeric and non-numeric models.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-numeric-model-use-case">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Numeric Model
<a class="headerlink leafygreen-ui-1kepx47" href="#numeric-model" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="numeric-model">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The numeric model may be appropriate if you need to query the
database for exact, mathematically valid matches or need to perform
server-side arithmetic, e.g.,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/inc/#mongodb-update-up.-inc">
<code class="leafygreen-ui-1l06pbn">
$inc
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/mul/#mongodb-update-up.-mul">
<code class="leafygreen-ui-1l06pbn">
$mul
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-agg-quick-ref-operator-arithmetic">
aggregation pipeline arithmetic
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
The following approaches follow the numeric model:
</strong>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-numeric-decimal" target="_self">
<span>
Using the Decimal BSON Type
</span>
</a>
which is a decimal-based
floating-point format capable of providing exact precision.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-numeric-scale-factor" target="_self">
<span>
Using a Scale Factor
</span>
</a>
to convert the monetary value
to a 64-bit integer (
<code class="leafygreen-ui-1l06pbn">
long
</code>
BSON type) by multiplying by a power of
10 scale factor.
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-non-numeric-model-use-case">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Non-Numeric Model
<a class="headerlink leafygreen-ui-1kepx47" href="#non-numeric-model" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="non-numeric-model">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If there is no need to perform server-side arithmetic on monetary data
or if server-side approximations are sufficient, modeling monetary data
using the non-numeric model may be suitable.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
The following approach follows the non-numeric model:
</strong>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-monetary-value-non-numeric" target="_self">
<span>
Using two fields for the monetary value
</span>
</a>
:
One field stores the exact monetary value as a
non-numeric
<code class="leafygreen-ui-1l06pbn">
string
</code>
and another field stores a binary-based
floating-point (
<code class="leafygreen-ui-1l06pbn">
double
</code>
BSON type) approximation of the value.
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Arithmetic mentioned on this page refers to server-side
arithmetic performed by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
, and
not to client-side arithmetic.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-monetary-value-numeric">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Numeric Model
<a class="headerlink leafygreen-ui-1kepx47" href="#numeric-model-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="numeric-model-1">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-numeric-decimal">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Using the Decimal BSON Type
<a class="headerlink leafygreen-ui-1kepx47" href="#using-the-decimal-bson-type" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="using-the-decimal-bson-type">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
decimal128
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON type
</a>
uses the IEEE 754
<code class="leafygreen-ui-1l06pbn">
decimal128
</code>
decimal-based floating-point numbering format. Unlike
binary-based floating-point formats such as the
<code class="leafygreen-ui-1l06pbn">
double
</code>
BSON type,
<code class="leafygreen-ui-1l06pbn">
decimal128
</code>
does not approximate decimal values and is able to
provide the exact precision required for working with monetary data.
</p>
<p class="leafygreen-ui-1kp3ins">
In
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
,
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
values are assigned and queried
using the
<code class="leafygreen-ui-1l06pbn">
Decimal128()
</code>
constructor. The following example adds a
document containing gas prices to a
<code class="leafygreen-ui-1l06pbn">
gasprices
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.gasprices.insertOne(\n {\n \"date\" : ISODate(),\n \"price\" : Decimal128(\"2.099\"),\n \"station\" : \"Quikstop\",\n \"grade\" : \"regular\"\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">gasprices</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<!-- -->)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"2.099"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"station"</span> <!-- -->: <span class="lg-highlight-string">"Quikstop"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-string">"regular"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following query matches the document above:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.gasprices.find( { price: Decimal128(\"2.099\") } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">gasprices</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"2.099"</span>) } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on the
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
type, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self">
<span>
Decimal128
<!-- -->
.
</span>
</a>
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Converting Values to Decimal
<a class="headerlink leafygreen-ui-1kepx47" href="#converting-values-to-decimal" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="converting-values-to-decimal">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
A collection's values can be transformed to the
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
type by
performing a one-time transformation or by modifying application logic
to perform the transformation as it accesses records.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Alternative to the procedure outlined below, starting in version
4.0, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/convert/#mongodb-expression-exp.-convert">
<code class="leafygreen-ui-1l06pbn">
$convert
</code>
</a>
and its helper
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/toDecimal/#mongodb-expression-exp.-toDecimal">
<code class="leafygreen-ui-1l06pbn">
$toDecimal
</code>
</a>
operator to convert values to
<code class="leafygreen-ui-1l06pbn">
Decimal128()
</code>
.
</p>
</div>
</div>
<section>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
One-Time Collection Transformation
<a class="headerlink leafygreen-ui-1kepx47" href="#one-time-collection-transformation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="one-time-collection-transformation">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
A collection can be transformed by iterating over all documents in the
collection, converting the monetary value to the
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
type, and
writing the document back to the collection.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
It is strongly advised to add the
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
value to the
document as a new field and remove the old field later once the
new field's values have been verified.
</p>
</div>
</div>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Be sure to test
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
conversions in an
isolated test environment. Once datafiles are created or modified
they will no longer be compatible with previous versions and there is no
support for downgrading datafiles containing decimals.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<strong>
Scale Factor Transformation:
</strong>
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following collection which used the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-numeric-scale-factor" target="_self">
<span>
Scale Factor
</span>
</a>
approach and saved
the monetary value as a 64-bit integer representing the number of cents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"description\" : \"T-Shirt\", \"size\" : \"M\", \"price\" : NumberLong(\"1999\") },\n{ \"_id\" : 2, \"description\" : \"Jeans\", \"size\" : \"36\", \"price\" : NumberLong(\"3999\") },\n{ \"_id\" : 3, \"description\" : \"Shorts\", \"size\" : \"32\", \"price\" : NumberLong(\"2999\") },\n{ \"_id\" : 4, \"description\" : \"Cool T-Shirt\", \"size\" : \"L\", \"price\" : NumberLong(\"2495\") },\n{ \"_id\" : 5, \"description\" : \"Designer Jeans\", \"size\" : \"30\", \"price\" : NumberLong(\"8000\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"M"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"1999"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"36"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"3999"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Shorts"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"32"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"2999"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Cool T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"L"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"2495"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Designer Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"30"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"8000"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
long
</code>
value can be converted to an appropriately formatted
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
value by multiplying
<code class="leafygreen-ui-1l06pbn">
price
</code>
and
<code class="leafygreen-ui-1l06pbn">
NumberDecimal("0.01")
</code>
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/multiply/#mongodb-expression-exp.-multiply">
<code class="leafygreen-ui-1l06pbn">
$multiply
</code>
</a>
operator.
The following aggregation pipeline assigns the converted value to the
new
<code class="leafygreen-ui-1l06pbn">
priceDec
</code>
field in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
<code class="leafygreen-ui-1l06pbn">
$addFields
</code>
</a>
stage:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.clothes.aggregate(\n [\n { $match: { price: { $type: \"long\" }, priceDec: { $exists: 0 } } },\n {\n $addFields: {\n priceDec: {\n $multiply: [ \"$price\", NumberDecimal( \"0.01\" ) ]\n }\n }\n }\n ]\n).forEach( ( function( doc ) {\n db.clothes.replaceOne( doc );\n} ) )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">clothes</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">price</span>: <!-- -->{ <span class="lg-highlight-attr">$type</span>: <span class="lg-highlight-string">"long"</span> }<!-- -->, <span class="lg-highlight-attr">priceDec</span>: <!-- -->{ <span class="lg-highlight-attr">$exists</span>: <span class="lg-highlight-number">0</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$addFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">priceDec</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$multiply</span>: <!-- -->[ <span class="lg-highlight-string">"$price"</span>, <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>( <span class="lg-highlight-string">"0.01"</span> ) ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">).<span class="lg-highlight-title lg-highlight-function">forEach</span>( <!-- -->( <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params"> doc </span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">clothes</span>.<span class="lg-highlight-title lg-highlight-function">replaceOne</span>( <!-- -->doc )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} ) )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The results of the aggregation pipeline can be verified using the
<code class="leafygreen-ui-1l06pbn">
db.clothes.find()
</code>
query:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"description\" : \"T-Shirt\", \"size\" : \"M\", \"price\" : NumberLong(1999), \"priceDec\" : NumberDecimal(\"19.99\") }\n{ \"_id\" : 2, \"description\" : \"Jeans\", \"size\" : \"36\", \"price\" : NumberLong(3999), \"priceDec\" : NumberDecimal(\"39.99\") }\n{ \"_id\" : 3, \"description\" : \"Shorts\", \"size\" : \"32\", \"price\" : NumberLong(2999), \"priceDec\" : NumberDecimal(\"29.99\") }\n{ \"_id\" : 4, \"description\" : \"Cool T-Shirt\", \"size\" : \"L\", \"price\" : NumberLong(2495), \"priceDec\" : NumberDecimal(\"24.95\") }\n{ \"_id\" : 5, \"description\" : \"Designer Jeans\", \"size\" : \"30\", \"price\" : NumberLong(8000), \"priceDec\" : NumberDecimal(\"80.00\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"M"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">1999</span>)<!-- -->, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"19.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"36"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">3999</span>)<!-- -->, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"39.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Shorts"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"32"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">2999</span>)<!-- -->, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"29.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Cool T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"L"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">2495</span>)<!-- -->, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"24.95"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Designer Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"30"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">8000</span>)<!-- -->, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"80.00"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you do not want to add a new field with the
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
value, the
original field can be overwritten. The following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#mongodb-method-db.collection.updateMany">
<code class="leafygreen-ui-1l06pbn">
updateMany()
</code>
</a>
method first checks that
<code class="leafygreen-ui-1l06pbn">
price
</code>
exists and that it is a
<code class="leafygreen-ui-1l06pbn">
long
</code>
, then transforms the
<code class="leafygreen-ui-1l06pbn">
long
</code>
value to
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
and stores it in the
<code class="leafygreen-ui-1l06pbn">
price
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.clothes.updateMany(\n { price: { $type: \"long\" } },\n { $mul: { price: NumberDecimal( \"0.01\" ) } }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">clothes</span>.<span class="lg-highlight-title lg-highlight-function">updateMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">price</span>: <!-- -->{ <span class="lg-highlight-attr">$type</span>: <span class="lg-highlight-string">"long"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$mul</span>: <!-- -->{ <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>( <span class="lg-highlight-string">"0.01"</span> ) } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The results can be verified using the
<code class="leafygreen-ui-1l06pbn">
db.clothes.find()
</code>
query:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"description\" : \"T-Shirt\", \"size\" : \"M\", \"price\" : NumberDecimal(\"19.99\") }\n{ \"_id\" : 2, \"description\" : \"Jeans\", \"size\" : \"36\", \"price\" : NumberDecimal(\"39.99\") }\n{ \"_id\" : 3, \"description\" : \"Shorts\", \"size\" : \"32\", \"price\" : NumberDecimal(\"29.99\") }\n{ \"_id\" : 4, \"description\" : \"Cool T-Shirt\", \"size\" : \"L\", \"price\" : NumberDecimal(\"24.95\") }\n{ \"_id\" : 5, \"description\" : \"Designer Jeans\", \"size\" : \"30\", \"price\" : NumberDecimal(\"80.00\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"M"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"19.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"36"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"39.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Shorts"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"32"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"29.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Cool T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"L"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"24.95"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Designer Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"30"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"80.00"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<strong>
Non-Numeric Transformation:
</strong>
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following collection which used the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-monetary-value-non-numeric" target="_self">
<span>
non-numeric
</span>
</a>
model and saved the monetary value as a
<code class="leafygreen-ui-1l06pbn">
string
</code>
with the exact
representation of the value:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"description\" : \"T-Shirt\", \"size\" : \"M\", \"price\" : \"19.99\" }\n{ \"_id\" : 2, \"description\" : \"Jeans\", \"size\" : \"36\", \"price\" : \"39.99\" }\n{ \"_id\" : 3, \"description\" : \"Shorts\", \"size\" : \"32\", \"price\" : \"29.99\" }\n{ \"_id\" : 4, \"description\" : \"Cool T-Shirt\", \"size\" : \"L\", \"price\" : \"24.95\" }\n{ \"_id\" : 5, \"description\" : \"Designer Jeans\", \"size\" : \"30\", \"price\" : \"80.00\" }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"M"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"19.99"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"36"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"39.99"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Shorts"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"32"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"29.99"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Cool T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"L"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"24.95"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Designer Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"30"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"80.00"</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following function first checks that
<code class="leafygreen-ui-1l06pbn">
price
</code>
exists and that it
is a
<code class="leafygreen-ui-1l06pbn">
string
</code>
, then transforms the
<code class="leafygreen-ui-1l06pbn">
string
</code>
value to a
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
value and stores it in the
<code class="leafygreen-ui-1l06pbn">
priceDec
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.clothes.find( { $and : [ { price: { $exists: true } }, { price: { $type: \"string\" } } ] } ).forEach( function( doc ) {\n doc.priceDec = NumberDecimal( doc.price );\n db.clothes.replaceOne( doc );\n} );","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">clothes</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <!-- -->$and<!-- --> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">price</span>: <!-- -->{ <span class="lg-highlight-attr">$exists</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">price</span>: <!-- -->{ <span class="lg-highlight-attr">$type</span>: <span class="lg-highlight-string">"string"</span> } } ] } ).<span class="lg-highlight-title lg-highlight-function">forEach</span>( <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params"> doc </span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->doc.<span class="lg-highlight-property">priceDec</span> <!-- -->= <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>( <!-- -->doc.<span class="lg-highlight-property">price</span> )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->db.<span class="lg-highlight-property">clothes</span>.<span class="lg-highlight-title lg-highlight-function">replaceOne</span>( <!-- -->doc )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The function does not output anything to the command line. The results
can be verified using the
<code class="leafygreen-ui-1l06pbn">
db.clothes.find()
</code>
query:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"description\" : \"T-Shirt\", \"size\" : \"M\", \"price\" : \"19.99\", \"priceDec\" : NumberDecimal(\"19.99\") }\n{ \"_id\" : 2, \"description\" : \"Jeans\", \"size\" : \"36\", \"price\" : \"39.99\", \"priceDec\" : NumberDecimal(\"39.99\") }\n{ \"_id\" : 3, \"description\" : \"Shorts\", \"size\" : \"32\", \"price\" : \"29.99\", \"priceDec\" : NumberDecimal(\"29.99\") }\n{ \"_id\" : 4, \"description\" : \"Cool T-Shirt\", \"size\" : \"L\", \"price\" : \"24.95\", \"priceDec\" : NumberDecimal(\"24.95\") }\n{ \"_id\" : 5, \"description\" : \"Designer Jeans\", \"size\" : \"30\", \"price\" : \"80.00\", \"priceDec\" : NumberDecimal(\"80.00\") }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"M"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"19.99"</span>, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"19.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"36"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"39.99"</span>, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"39.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Shorts"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"32"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"29.99"</span>, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"29.99"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Cool T-Shirt"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"L"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"24.95"</span>, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"24.95"</span>) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"Designer Jeans"</span>, <span class="lg-highlight-string">"size"</span> <!-- -->: <span class="lg-highlight-string">"30"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-string">"80.00"</span>, <span class="lg-highlight-string">"priceDec"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"80.00"</span>) }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Application Logic Transformation
<a class="headerlink leafygreen-ui-1kepx47" href="#application-logic-transformation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="application-logic-transformation">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
It is possible to perform the transformation to the
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
type from within the application logic. In this scenario the
application modified to perform the transformation as it accesses
records.
</p>
<p class="leafygreen-ui-1kp3ins">
The typical application logic is as follows:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Test that the new field exists and that it is of
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
type
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the new
<code class="leafygreen-ui-1l06pbn">
decimal
</code>
field does not exist:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Create it by properly converting old field values
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Remove the old field
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Persist the transformed record
</p>
</li>
</ul>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-numeric-scale-factor">
</span>
</section>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Using a Scale Factor
<a class="headerlink leafygreen-ui-1kepx47" href="#using-a-scale-factor" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="using-a-scale-factor">
</div>
</a>
</h3>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-numeric-decimal" target="_self">
<span>
decimal
</span>
</a>
type for modeling
monetary data is preferred over the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-numeric-scale-factor" target="_self">
<span>
Scale Factor
</span>
</a>
method.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To model monetary data using the scale factor approach:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Determine the maximum precision needed for the monetary value. For
example, your application may require precision down to the tenth of
one cent for monetary values in
<code class="leafygreen-ui-1l06pbn">
USD
</code>
currency.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Convert the monetary value into an integer by multiplying the value
by a power of 10 that ensures the maximum precision needed becomes the
least significant digit of the integer. For example, if the required
maximum precision is the tenth of one cent, multiply the monetary value
by 1000.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Store the converted monetary value.
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
For example, the following scales
<code class="leafygreen-ui-1l06pbn">
9.99 USD
</code>
by 1000 to preserve
precision up to one tenth of a cent.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ price: 9990, currency: \"USD\" }","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ price: 9990, currency: <span class="lg-highlight-string">"USD"</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The model assumes that for a given currency value:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The scale factor is consistent for a currency; i.e. same scaling
factor for a given currency.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The scale factor is a constant and known property of the currency;
i.e applications can determine the scale factor from the currency.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
When using this model, applications must be consistent in performing
the appropriate scaling of the values.
</p>
<p class="leafygreen-ui-1kp3ins">
For use cases of this model, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-numeric-model-use-case" target="_self">
<span>
Numeric Model
<!-- -->
.
</span>
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-monetary-value-non-numeric">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Non-Numeric Model
<a class="headerlink leafygreen-ui-1kepx47" href="#non-numeric-model-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="non-numeric-model-1">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To model monetary data using the non-numeric model, store the
value in two fields:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In one field, encode the exact monetary value as a non-numeric data
type; e.g.,
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
or a
<code class="leafygreen-ui-1l06pbn">
string
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In the second field, store a double-precision floating point
approximation of the exact value.
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
The following example uses the non-numeric model to store
<code class="leafygreen-ui-1l06pbn">
9.99 USD
</code>
for the price and
<code class="leafygreen-ui-1l06pbn">
0.25 USD
</code>
for the fee:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n price: { display: \"9.99\", approx: 9.9900000000000002, currency: \"USD\" },\n fee: { display: \"0.25\", approx: 0.2499999999999999, currency: \"USD\" }\n}","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> price: { display: <span class="lg-highlight-string">"9.99"</span>, approx: 9.9900000000000002, currency: <span class="lg-highlight-string">"USD"</span> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> fee: { display: <span class="lg-highlight-string">"0.25"</span>, approx: 0.2499999999999999, currency: <span class="lg-highlight-string">"USD"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
With some care, applications can perform range and sort queries on the
field with the numeric approximation. However, the use of the approximation
field for the query and sort operations requires that applications
perform client-side post-processing to decode the non-numeric
representation of the exact value and then filter out the returned
documents based on the exact monetary value.
</p>
<p class="leafygreen-ui-1kp3ins">
For use cases of this model, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-non-numeric-model-use-case" target="_self">
<span>
Non-Numeric Model
<!-- -->
.
</span>
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/applications/data-models-applications/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Specific Application Contexts
<a class="headerlink leafygreen-ui-1kepx47" href="#model-specific-application-contexts" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-specific-application-contexts">
</div>
</a>
</h1>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-data-for-atomic-operations/">
Model Data for Atomic Operations
</a>
</dt>
<dd class="css-1ufxuu7">
Illustrates how embedding fields related to an atomic update
within the same document ensures that the fields are in sync.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-data-for-keyword-search/">
Model Data to Support Keyword Search
</a>
</dt>
<dd class="css-1ufxuu7">
Describes one method for supporting keyword search by storing
keywords in an array in the same document as the text field.
Combined with a multi-key index, this pattern can support
application's keyword search operations.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-monetary-data/">
Model Monetary Data
</a>
</dt>
<dd class="css-1ufxuu7">
Describes two methods to model monetary data in MongoDB.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-iot-data/">
Model IoT Data
</a>
</dt>
<dd class="css-1ufxuu7">
Describes how to deal with IoT data in MongoDB.
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-tree-structures-with-nested-sets/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Tree Structures with Nested Sets
<a class="headerlink leafygreen-ui-1kepx47" href="#model-tree-structures-with-nested-sets" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-tree-structures-with-nested-sets">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#pattern" target="_self">
<span>
Pattern
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This document describes a data model that describes a tree like
structure that optimizes discovering subtrees at the expense of tree
mutability.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="pattern">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<em>
Nested Sets
</em>
pattern identifies each node in the tree as stops in
a round-trip traversal of the tree. The application visits each node
in the tree twice; first during the initial trip, and second during
the return trip. The
<em>
Nested Sets
</em>
pattern stores each tree node in a
document; in addition to the tree node, document stores the ID of
node's parent, the node's initial stop in the
<code class="leafygreen-ui-1l06pbn">
left
</code>
field, and its
return stop in the
<code class="leafygreen-ui-1l06pbn">
right
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following hierarchy of categories:
</p>
<div class="figure css-5vkxs0" style="width:720px">
<img alt="Example of a hierarchical data. The numbers identify the stops at nodes during a roundtrip traversal of a tree." class="leafygreen-ui-1qnf57e" height="400" src="/docs/manual/images/data-model-example-nested-set.bakedsvg.svg" style="--border-color:#C1C7C6" width="710"/>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example models the tree using
<em>
Nested Sets
</em>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.insertMany( [\n { _id: \"Books\", parent: 0, left: 1, right: 12 },\n { _id: \"Programming\", parent: \"Books\", left: 2, right: 11 },\n { _id: \"Languages\", parent: \"Programming\", left: 3, right: 4 },\n { _id: \"Databases\", parent: \"Programming\", left: 5, right: 10 },\n { _id: \"MongoDB\", parent: \"Databases\", left: 6, right: 7 },\n { _id: \"dbm\", parent: \"Databases\", left: 8, right: 9 }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">left</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">right</span>: <span class="lg-highlight-number">12</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Programming"</span>, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-attr">left</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">right</span>: <span class="lg-highlight-number">11</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Languages"</span>, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Programming"</span>, <span class="lg-highlight-attr">left</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">right</span>: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Databases"</span>, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Programming"</span>, <span class="lg-highlight-attr">left</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">right</span>: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"MongoDB"</span>, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Databases"</span>, <span class="lg-highlight-attr">left</span>: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-attr">right</span>: <span class="lg-highlight-number">7</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"dbm"</span>, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Databases"</span>, <span class="lg-highlight-attr">left</span>: <span class="lg-highlight-number">8</span>, <span class="lg-highlight-attr">right</span>: <span class="lg-highlight-number">9</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can query to retrieve the descendants of a node:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var databaseCategory = db.categories.findOne( { _id: \"Databases\" } );\ndb.categories.find( { left: { $gt: databaseCategory.left }, right: { $lt: databaseCategory.right } } );","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> databaseCategory <!-- -->= <!-- -->db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">findOne</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Databases"</span> } )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">left</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <!-- -->databaseCategory.<span class="lg-highlight-property">left</span> }<!-- -->, <span class="lg-highlight-attr">right</span>: <!-- -->{ <span class="lg-highlight-attr">$lt</span>: <!-- -->databaseCategory.<span class="lg-highlight-property">right</span> } } )<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<em>
Nested Sets
</em>
pattern provides a fast and efficient solution for
finding subtrees but is inefficient for modifying the tree structure.
As such, this pattern is best for static trees that do not change.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-tree-structures-with-materialized-paths/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Tree Structures with Materialized Paths
<a class="headerlink leafygreen-ui-1kepx47" href="#model-tree-structures-with-materialized-paths" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-tree-structures-with-materialized-paths">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#pattern" target="_self">
<span>
Pattern
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This page describes a data model that describes a tree-like
structure in MongoDB documents by storing full relationship paths
between documents.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="pattern">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<em>
Materialized Paths
</em>
pattern stores each tree node in a document;
in addition to the tree node, document stores as a string the id(s) of
the node's ancestors or path. Although the
<em>
Materialized Paths
</em>
pattern
requires additional steps of working with strings and regular
expressions, the pattern also provides more flexibility in working with
the path, such as finding nodes by partial paths.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following hierarchy of categories:
</p>
<div class="figure css-5vkxs0" style="width:760px">
<img alt="Tree data model for a sample hierarchy of categories." class="leafygreen-ui-1qnf57e" height="400" src="/docs/manual/images/data-model-tree.bakedsvg.svg" style="--border-color:#C1C7C6" width="540"/>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example models the tree using
<em>
Materialized Paths
</em>
,
storing the path in the field
<code class="leafygreen-ui-1l06pbn">
path
</code>
; the path string uses the comma
<code class="leafygreen-ui-1l06pbn">
,
</code>
as a delimiter:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.insertMany( [\n { _id: \"Books\", path: null },\n { _id: \"Programming\", path: \",Books,\" },\n { _id: \"Databases\", path: \",Books,Programming,\" },\n { _id: \"Languages\", path: \",Books,Programming,\" },\n { _id: \"MongoDB\", path: \",Books,Programming,Databases,\" },\n { _id: \"dbm\", path: \",Books,Programming,Databases,\" }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-literal">null</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Programming"</span>, <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">",Books,"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Databases"</span>, <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">",Books,Programming,"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Languages"</span>, <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">",Books,Programming,"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"MongoDB"</span>, <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">",Books,Programming,Databases,"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"dbm"</span>, <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-string">",Books,Programming,Databases,"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can query to retrieve the whole tree, sorting by the field
<code class="leafygreen-ui-1l06pbn">
path
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.find().sort( { path: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">sort</span>( <!-- -->{ <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can use regular expressions on the
<code class="leafygreen-ui-1l06pbn">
path
</code>
field to find the
descendants of
<code class="leafygreen-ui-1l06pbn">
Programming
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.find( { path: /,Programming,/ } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-regexp">/,Programming,/</span> <!-- -->} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can also retrieve the descendants of
<code class="leafygreen-ui-1l06pbn">
Books
</code>
where the
<code class="leafygreen-ui-1l06pbn">
Books
</code>
is also at the topmost level of the hierarchy:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.find( { path: /^,Books,/ } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-regexp">/^,Books,/</span> <!-- -->} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To create an index on the field
<code class="leafygreen-ui-1l06pbn">
path
</code>
use the following
invocation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.createIndex( { path: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">path</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This index may improve performance depending on the query:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For queries from the root
<code class="leafygreen-ui-1l06pbn">
Books
</code>
sub-tree (e.g.
<code class="leafygreen-ui-1l06pbn">
/^,Books,/
</code>
or
<code class="leafygreen-ui-1l06pbn">
/^,Books,Programming,/
</code>
), an index on the
<code class="leafygreen-ui-1l06pbn">
path
</code>
field
improves the query performance significantly.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For queries of sub-trees where the path from the root is not
provided in the query (e.g.
<code class="leafygreen-ui-1l06pbn">
/,Databases,/
</code>
), or similar queries
of sub-trees, where the node might be in the middle of the indexed
string, the query must inspect the entire index.
</p>
<p class="leafygreen-ui-1kp3ins">
For these queries an index
<em>
may
</em>
provide some performance
improvement
<em>
if
</em>
the index is significantly smaller than the
entire collection.
</p>
</li>
</ul>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-tree-structures-with-ancestors-array/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Tree Structures with an Array of Ancestors
<a class="headerlink leafygreen-ui-1kepx47" href="#model-tree-structures-with-an-array-of-ancestors" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-tree-structures-with-an-array-of-ancestors">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#pattern" target="_self">
<span>
Pattern
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This page describes a data model that describes a tree-like
structure in MongoDB documents using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-referencing">
references
</a>
to parent nodes and an array that stores
all ancestors.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="pattern">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<em>
Array of Ancestors
</em>
pattern stores each tree node in a document;
in addition to the tree node, document stores in an array the id(s) of
the node's ancestors or path.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following hierarchy of categories:
</p>
<div class="figure css-5vkxs0" style="width:760px">
<img alt="Tree data model for a sample hierarchy of categories." class="leafygreen-ui-1qnf57e" height="400" src="/docs/manual/images/data-model-tree.bakedsvg.svg" style="--border-color:#C1C7C6" width="540"/>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example models the tree using
<em>
Array of Ancestors
</em>
. In
addition to the
<code class="leafygreen-ui-1l06pbn">
ancestors
</code>
field, these documents also store the
reference to the immediate parent category in the
<code class="leafygreen-ui-1l06pbn">
parent
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.insertMany( [\n { _id: \"MongoDB\", ancestors: [ \"Books\", \"Programming\", \"Databases\" ], parent: \"Databases\" },\n { _id: \"dbm\", ancestors: [ \"Books\", \"Programming\", \"Databases\" ], parent: \"Databases\" },\n { _id: \"Databases\", ancestors: [ \"Books\", \"Programming\" ], parent: \"Programming\" },\n { _id: \"Languages\", ancestors: [ \"Books\", \"Programming\" ], parent: \"Programming\" },\n { _id: \"Programming\", ancestors: [ \"Books\" ], parent: \"Books\" },\n { _id: \"Books\", ancestors: [ ], parent: null }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"MongoDB"</span>, <span class="lg-highlight-attr">ancestors</span>: <!-- -->[ <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-string">"Programming"</span>, <span class="lg-highlight-string">"Databases"</span> ]<!-- -->, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Databases"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"dbm"</span>, <span class="lg-highlight-attr">ancestors</span>: <!-- -->[ <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-string">"Programming"</span>, <span class="lg-highlight-string">"Databases"</span> ]<!-- -->, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Databases"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Databases"</span>, <span class="lg-highlight-attr">ancestors</span>: <!-- -->[ <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-string">"Programming"</span> ]<!-- -->, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Programming"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Languages"</span>, <span class="lg-highlight-attr">ancestors</span>: <!-- -->[ <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-string">"Programming"</span> ]<!-- -->, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Programming"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Programming"</span>, <span class="lg-highlight-attr">ancestors</span>: <!-- -->[ <span class="lg-highlight-string">"Books"</span> ]<!-- -->, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-string">"Books"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-attr">ancestors</span>: <!-- -->[ <!-- -->]<!-- -->, <span class="lg-highlight-attr">parent</span>: <span class="lg-highlight-literal">null</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The query to retrieve the ancestors or path of a node is fast and
straightforward:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.findOne( { _id: \"MongoDB\" } ).ancestors","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">findOne</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"MongoDB"</span> } ).<span class="lg-highlight-property">ancestors</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can create an index on the field
<code class="leafygreen-ui-1l06pbn">
ancestors
</code>
to enable fast
search by the ancestors nodes:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.createIndex( { ancestors: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">ancestors</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can query by the field
<code class="leafygreen-ui-1l06pbn">
ancestors
</code>
to find all its descendants:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.find( { ancestors: \"Programming\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">ancestors</span>: <span class="lg-highlight-string">"Programming"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The
<em>
Array of Ancestors
</em>
pattern provides a fast and efficient solution
to find the descendants and the ancestors of a node by creating an
index on the elements of the ancestors field. This makes
<em>
Array of
Ancestors
</em>
a good choice for working with subtrees.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<em>
Array of Ancestors
</em>
pattern is slightly slower than the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/model-tree-structures-with-materialized-paths/">
Materialized Paths
</a>
pattern but
is more straightforward to use.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-data-for-keyword-search/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Data to Support Keyword Search
<a class="headerlink leafygreen-ui-1kepx47" href="#model-data-to-support-keyword-search" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-data-to-support-keyword-search">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#pattern" target="_self">
<span>
Pattern
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#limitations-of-keyword-indexes" target="_self">
<span>
Limitations of Keyword Indexes
</span>
</a>
</li>
</ul>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Keyword search is
<em>
not
</em>
the same as text search or full text
search, and does not provide stemming or other text-processing
features. See the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-limit-keyword-indexes" target="_self">
<span>
Limitations of Keyword Indexes
</span>
</a>
section for more
information.
</p>
<p class="leafygreen-ui-1kp3ins">
In 2.4, MongoDB provides a text search feature. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-text/#std-label-index-type-text">
Text Indexes on Self-Managed Deployments
</a>
for more information.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If your application needs to perform queries on the content of a field
that holds text you can perform exact matches on the text or use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/regex/#mongodb-query-op.-regex">
<code class="leafygreen-ui-1l06pbn">
$regex
</code>
</a>
to use regular expression pattern matches. However,
for many operations on text, these methods do not satisfy application
requirements.
</p>
<p class="leafygreen-ui-1kp3ins">
This pattern describes one method for supporting keyword search using
MongoDB to support application search functionality, that uses
keywords stored in an array in the same document as the text
field. Combined with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-multikey/#std-label-index-type-multikey">
multi-key index
</a>
,
this pattern can support application's keyword search operations.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="pattern">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To add structures to your document to support keyword-based queries,
create an array field in your documents and add the keywords as
strings in the array. You can then create a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-multikey/#std-label-index-type-multi-key">
multi-key index
</a>
on the array and create queries that select
values from the array.
</p>
<div class="leafygreen-ui-vg7qwp" role="note">
<h2 class="leafygreen-ui-2xicti">
Example
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Given a collection of library volumes that you want to provide
topic-based search. For each volume, you add the array
<code class="leafygreen-ui-1l06pbn">
topics
</code>
,
and you add as many keywords as needed for a given volume.
</p>
<p class="leafygreen-ui-1kp3ins">
For the
<code class="leafygreen-ui-1l06pbn">
Moby-Dick
</code>
volume you might have the following document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ title : \"Moby-Dick\" ,\n author : \"Herman Melville\" ,\n published : 1851 ,\n ISBN : 0451526996 ,\n topics : [ \"whaling\" , \"allegory\" , \"revenge\" , \"American\" ,\n \"novel\" , \"nautical\" , \"voyage\" , \"Cape Cod\" ]\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <!-- -->title <!-- -->: <span class="lg-highlight-string">"Moby-Dick"</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->author <!-- -->: <span class="lg-highlight-string">"Herman Melville"</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->published <!-- -->: <span class="lg-highlight-number">1851</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable lg-highlight-constant">ISBN</span> <!-- -->: <span class="lg-highlight-number">0451526996</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->topics <!-- -->: <!-- -->[ <span class="lg-highlight-string">"whaling"</span> <!-- -->, <span class="lg-highlight-string">"allegory"</span> <!-- -->, <span class="lg-highlight-string">"revenge"</span> <!-- -->, <span class="lg-highlight-string">"American"</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"novel"</span> <!-- -->, <span class="lg-highlight-string">"nautical"</span> <!-- -->, <span class="lg-highlight-string">"voyage"</span> <!-- -->, <span class="lg-highlight-string">"Cape Cod"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You then create a multi-key index on the
<code class="leafygreen-ui-1l06pbn">
topics
</code>
array:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.volumes.createIndex( { topics: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">volumes</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">topics</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The multi-key index creates separate index entries for each keyword in
the
<code class="leafygreen-ui-1l06pbn">
topics
</code>
array. For example the index contains one entry for
<code class="leafygreen-ui-1l06pbn">
whaling
</code>
and another for
<code class="leafygreen-ui-1l06pbn">
allegory
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
You then query based on the keywords. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.volumes.findOne( { topics : \"voyage\" }, { title: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">volumes</span>.<span class="lg-highlight-title lg-highlight-function">findOne</span>( <!-- -->{ <!-- -->topics <!-- -->: <span class="lg-highlight-string">"voyage"</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">title</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
An array with a large number of elements, such as one with
several hundreds or thousands of keywords will incur greater
indexing costs on insertion.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-limit-keyword-indexes">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Limitations of Keyword Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#limitations-of-keyword-indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="limitations-of-keyword-indexes">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB can support keyword searches using specific data models and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-multikey/#std-label-index-type-multikey">
multi-key indexes
</a>
; however, these keyword
indexes are not sufficient or comparable to full-text products in the
following respects:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<em>
Stemming
</em>
. Keyword queries in MongoDB can not parse keywords for
root or related words.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<em>
Synonyms
</em>
. Keyword-based search features must provide support for
synonym or related queries in the application layer.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<em>
Ranking
</em>
. The keyword look ups described in this document do not
provide a way to weight results.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<em>
Asynchronous Indexing
</em>
. MongoDB builds indexes synchronously, which
means that the indexes used for keyword indexes are always current
and can operate in real-time. However, asynchronous bulk indexes
may be more efficient for some kinds of content and workloads.
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/rs.reconfigForPSASet/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
rs.reconfigForPSASet()
<a class="headerlink leafygreen-ui-1kepx47" href="#rs.reconfigforpsaset--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rs.reconfigforpsaset--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
rs.reconfigForPSASet( memberIndex, config, { options } )
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-rs.reconfigForPSASet" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-rs.reconfigForPSASet">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Safely perform some reconfiguration changes on a
primary-secondary-arbiter (PSA) replica set or on a replica set that
is changing to a PSA architecture. You should only use this method in
one of the following cases:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You want to reconfigure a secondary in an existing three-member
replica set with a PSA architecture to become a voting,
data-bearing node with a non-zero
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.priority">
<code class="leafygreen-ui-1l06pbn">
priority
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You want to add a new voting, data-bearing node with a non-zero
priority to an existing two-member replica set that contains one
voting, data-bearing node and one arbiter.
</p>
</li>
</ul>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If the secondary you are adding is lagged and the resulting
replica set is a PSA configuration, the first configuration change
will change the number of nodes that need to commit a change with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
. In this case, your commit point will
lag until the secondary has caught up.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For details about the behavior of this method, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-reconfigForPSASet-behavior" target="_self">
<span>
Behavior
<!-- -->
.
</span>
</a>
</p>
</dd>
</dl>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.reconfigForPSASet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.reconfigForPSASet()
</code>
</span>
</a>
method has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"rs.reconfigForPSASet(\n memberIndex: <num>,\n config: <configuration>,\n {\n \"force\" : <boolean>,\n \"maxTimeMS\" : <int>\n }\n)","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">rs.reconfigForPSASet(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> memberIndex: <num>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> config: <configuration>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"force"</span> : <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maxTimeMS"</span> : <int></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Parameter
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
memberIndex
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The index of the secondary that is being added or modified.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
config
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#std-label-replica-set-configuration-settings">
document
</a>
that
specifies the new configuration of a replica set.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
force
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
<strong class="css-4dei7l">
WARNING:
</strong>
Running the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.reconfigForPSASet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.reconfigForPSASet()
</code>
</span>
</a>
method with
<code class="leafygreen-ui-1l06pbn">
force: true
</code>
is not recommended and can lead to
committed writes being rolled back.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify
<code class="leafygreen-ui-1l06pbn">
true
</code>
to force the available replica set members to
accept the new configuration. Defaults to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Force reconfiguration can result in unexpected or undesired
behavior, including
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/#std-label-replica-set-rollbacks">
rollback
</a>
of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
committed writes.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies a cumulative time limit in milliseconds
for processing each reconfiguration during the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.reconfigForPSASet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.reconfigForPSASet()
</code>
</span>
</a>
operation. By default,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.reconfigForPSASet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.reconfigForPSASet()
</code>
</span>
</a>
waits indefinitely for the
replica configurations to propagate to a majority of replica
set members.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-reconfigForPSASet-behavior">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.reconfigForPSASet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.reconfigForPSASet()
</code>
</span>
</a>
method reconfigures your replica
set in two steps:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The method reconfigures your replica set to add or modify a secondary
with
<code class="leafygreen-ui-1l06pbn">
{ votes: 1, priority: 0 }
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Once the added or modified secondary has caught up with all committed
writes, the method reconfigures the secondary to have the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.priority">
<code class="leafygreen-ui-1l06pbn">
priority
</code>
</a>
specified in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.reconfigForPSASet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.reconfigForPSASet()
</code>
</span>
</a>
command
(
<code class="leafygreen-ui-1l06pbn">
{ votes: 1, priority: <num> }
</code>
).
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
The two-step approach avoids the possibility of rolling back committed
writes in the case of a failover to the new secondary before the new
secondary has all committed writes from the previous configuration.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-reconfigForPSASet-usage">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
A replica set named
<code class="leafygreen-ui-1l06pbn">
rs0
</code>
has the following configuration:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : \"rs0\",\n \"version\" : 1,\n \"term\": 1,\n \"members\" : [\n {\n \"_id\" : 0,\n \"host\" : \"mongodb0.example.net:27017\",\n \"arbiterOnly\" : false,\n \"buildIndexes\" : true,\n \"hidden\" : false,\n \"priority\" : 1,\n \"tags\" : {},\n \"secondaryDelaySecs\" : Long(\"0\"),\n \"votes\" : 1\n },\n {\n \"_id\" : 2,\n \"host\" : \"mongodb1.example.net:27017\",\n \"arbiterOnly\" : true,\n \"buildIndexes\" : true,\n \"hidden\" : false,\n \"priority\" : 0,\n \"tags\" : {},\n \"secondaryDelaySecs\" : Long(\"0\"),\n \"votes\" : 1\n }\n ],\n \"protocolVersion\" : Long(\"1\"),\n \"writeConcernMajorityJournalDefault\": true,\n \"settings\" : {\n \"chainingAllowed\" : true,\n \"heartbeatIntervalMillis\" : 2000,\n \"heartbeatTimeoutSecs\" : 10,\n \"electionTimeoutMillis\" : 10000,\n \"catchUpTimeoutMillis\" : 2000,\n \"getLastErrorModes\" : {},\n \"getLastErrorDefaults\" : {\n \"w\" : 1,\n \"wtimeout\" : 0\n },\n \"replicaSetId\" : ObjectId(\"60e6f83923193faa336889d2\")\n }\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"rs0"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"term"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"members"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"mongodb0.example.net:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"arbiterOnly"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"buildIndexes"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hidden"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"priority"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondaryDelaySecs"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"votes"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"mongodb1.example.net:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"arbiterOnly"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"buildIndexes"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hidden"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"priority"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondaryDelaySecs"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"votes"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"protocolVersion"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"1"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writeConcernMajorityJournalDefault"</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"settings"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"chainingAllowed"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"heartbeatIntervalMillis"</span> <!-- -->: <span class="lg-highlight-number">2000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"heartbeatTimeoutSecs"</span> <!-- -->: <span class="lg-highlight-number">10</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"electionTimeoutMillis"</span> <!-- -->: <span class="lg-highlight-number">10000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"catchUpTimeoutMillis"</span> <!-- -->: <span class="lg-highlight-number">2000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"getLastErrorModes"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"getLastErrorDefaults"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"wtimeout"</span> <!-- -->: <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"replicaSetId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"60e6f83923193faa336889d2"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following sequence of operations add a new secondary to the replica
set. The operations are issued in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
shell while
connected to the primary.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"cfg = rs.conf();\ncfg[\"members\"] = [\n {\n \"_id\" : 0,\n \"host\" : \"mongodb0.example.net:27017\",\n \"arbiterOnly\" : false,\n \"buildIndexes\" : true,\n \"hidden\" : false,\n \"priority\" : 1,\n \"tags\" : {},\n \"secondaryDelaySecs\" : Long(\"0\"),\n \"votes\" : 1\n },\n {\n \"_id\" : 1,\n \"host\" : \"mongodb1.example.net:27017\",\n \"arbiterOnly\" : false,\n \"buildIndexes\" : true,\n \"hidden\" : false,\n \"priority\" : 2,\n \"tags\" : {},\n \"secondaryDelaySecs\" : Long(\"0\"),\n \"votes\" : 1\n },\n {\n \"_id\" : 2,\n \"host\" : \"mongodb2.example.net:27017\",\n \"arbiterOnly\" : true,\n \"buildIndexes\" : true,\n \"hidden\" : false,\n \"priority\" : 0,\n \"tags\" : {},\n \"secondaryDelaySecs\" : Long(\"0\"),\n \"votes\" : 1\n }\n]\nrs.reconfigForPSASet(1, cfg);","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">cfg <!-- -->= <!-- -->rs.<span class="lg-highlight-title lg-highlight-function">conf</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">cfg<!-- -->[<span class="lg-highlight-string">"members"</span>] <!-- -->= <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"mongodb0.example.net:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"arbiterOnly"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"buildIndexes"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hidden"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"priority"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondaryDelaySecs"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"votes"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"mongodb1.example.net:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"arbiterOnly"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"buildIndexes"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hidden"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"priority"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondaryDelaySecs"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"votes"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"mongodb2.example.net:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"arbiterOnly"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"buildIndexes"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hidden"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"priority"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondaryDelaySecs"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"votes"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">rs.<span class="lg-highlight-title lg-highlight-function">reconfigForPSASet</span>(<span class="lg-highlight-number">1</span>, <!-- -->cfg)<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The first statement uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.conf/#mongodb-method-rs.conf">
<code class="leafygreen-ui-1l06pbn">
rs.conf()
</code>
</a>
method to retrieve
a document containing the current
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#std-label-replSetGetConfig-output">
configuration
</a>
for the replica set and stores the
document in the local variable
<code class="leafygreen-ui-1l06pbn">
cfg
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The second statement adds the new secondary to the
<code class="leafygreen-ui-1l06pbn">
members
</code>
array.
In this configuration the new secondary is added at
<code class="leafygreen-ui-1l06pbn">
memberIndex
</code>
<code class="leafygreen-ui-1l06pbn">
1
</code>
. The
<code class="leafygreen-ui-1l06pbn">
memberIndex
</code>
is the same as the array index. For
additional settings, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#std-label-replSetGetConfig-output">
replica set configuration settings
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The last statement calls the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.reconfigForPSASet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.reconfigForPSASet()
</code>
</span>
</a>
method
with the
<code class="leafygreen-ui-1l06pbn">
memberIndex
</code>
<code class="leafygreen-ui-1l06pbn">
1
</code>
and the modified
<code class="leafygreen-ui-1l06pbn">
cfg
</code>
. The
<code class="leafygreen-ui-1l06pbn">
memberIndex
</code>
is the array position of the new member in the
<code class="leafygreen-ui-1l06pbn">
members
</code>
array. Upon successful reconfiguration, the replica set
configuration resembles the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : \"rs0\",\n \"version\" : 1,\n \"term\": 1,\n \"members\" : [\n {\n \"_id\" : 0,\n \"host\" : \"mongodb0.example.net:27017\",\n \"arbiterOnly\" : false,\n \"buildIndexes\" : true,\n \"hidden\" : false,\n \"priority\" : 1,\n \"tags\" : {},\n \"secondaryDelaySecs\" : Long(\"0\"),\n \"votes\" : 1\n },\n {\n \"_id\" : 1,\n \"host\" : \"mongodb1.example.net:27017\",\n \"arbiterOnly\" : false,\n \"buildIndexes\" : true,\n \"hidden\" : false,\n \"priority\" : 2,\n \"tags\" : {},\n \"secondaryDelaySecs\" : Long(\"0\"),\n \"votes\" : 1\n },\n {\n \"_id\" : 2,\n \"host\" : \"mongodb2.example.net:27017\",\n \"arbiterOnly\" : true,\n \"buildIndexes\" : true,\n \"hidden\" : false,\n \"priority\" : 0,\n \"tags\" : {},\n \"secondaryDelaySecs\" : Long(\"0\"),\n \"votes\" : 1\n }\n ],\n \"protocolVersion\" : Long(\"1\"),\n \"writeConcernMajorityJournalDefault\": true,\n \"settings\" : {\n \"chainingAllowed\" : true,\n \"heartbeatIntervalMillis\" : 2000,\n \"heartbeatTimeoutSecs\" : 10,\n \"electionTimeoutMillis\" : 10000,\n \"catchUpTimeoutMillis\" : 2000,\n \"getLastErrorModes\" : {},\n \"getLastErrorDefaults\" : {\n \"w\" : 1,\n \"wtimeout\" : 0\n },\n \"replicaSetId\" : ObjectId(\"60e6f83923193faa336889d2\")\n }\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"rs0"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"term"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"members"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"mongodb0.example.net:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"arbiterOnly"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"buildIndexes"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hidden"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"priority"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondaryDelaySecs"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"votes"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"mongodb1.example.net:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"arbiterOnly"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"buildIndexes"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hidden"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"priority"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondaryDelaySecs"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"votes"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"mongodb2.example.net:27017"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"arbiterOnly"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"buildIndexes"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hidden"</span> <!-- -->: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"priority"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"secondaryDelaySecs"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"votes"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"protocolVersion"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"1"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"writeConcernMajorityJournalDefault"</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"settings"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"chainingAllowed"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"heartbeatIntervalMillis"</span> <!-- -->: <span class="lg-highlight-number">2000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"heartbeatTimeoutSecs"</span> <!-- -->: <span class="lg-highlight-number">10</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"electionTimeoutMillis"</span> <!-- -->: <span class="lg-highlight-number">10000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"catchUpTimeoutMillis"</span> <!-- -->: <span class="lg-highlight-number">2000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"getLastErrorModes"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"getLastErrorDefaults"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"w"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"wtimeout"</span> <!-- -->: <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"replicaSetId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"60e6f83923193faa336889d2"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
</ol>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.conf/#mongodb-method-rs.conf">
<code class="leafygreen-ui-1l06pbn">
rs.conf()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.reconfig/#mongodb-method-rs.reconfig">
<code class="leafygreen-ui-1l06pbn">
rs.reconfig()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#std-label-replSetGetConfig-output">
Replica Set Configuration Fields
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/replica-set-member-configuration/">
Self-Managed Member Configuration Tutorials
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/replica-set-maintenance/">
Self-Managed Replica Set Maintenance Tutorials
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/server-sessions/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Server Sessions
<a class="headerlink leafygreen-ui-1kepx47" href="#server-sessions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="server-sessions">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-options" target="_self">
<span>
Command Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sessions-commands" target="_self">
<span>
Sessions Commands
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sessions-and-access-control" target="_self">
<span>
Sessions and Access Control
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB's server sessions, or logical sessions, are the underlying
framework used by client sessions to support
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency">
Causal Consistency
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/#std-label-retryable-writes">
retryable writes
<!-- -->
.
</a>
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Applications use client sessions to interface with server sessions.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Server sessions are available for replica sets and sharded clusters only.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Command Options
<a class="headerlink leafygreen-ui-1kepx47" href="#command-options" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in 3.6, MongoDB drivers associate all operations with a server
session, with the exception of unacknowledged writes. The following
options are available for all commands to support association with a
server session:
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
and the drivers assign these options
to the commands in the session.
</p>
</div>
</div>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:15%"/>
<col style="width:15%"/>
<col style="width:50%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Option
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
lsid
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The document that specifies the unique ID of the session
associated with the command. If the
<code class="leafygreen-ui-1l06pbn">
txnNumber
</code>
is
specified, the
<code class="leafygreen-ui-1l06pbn">
lsid
</code>
is required.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
txnNumber
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
64-bit integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A strictly increasing non-negative number that uniquely
identifies the command in the command's session.
</p>
<p class="leafygreen-ui-1kp3ins">
If specified, the command must also include the
<code class="leafygreen-ui-1l06pbn">
lsid
</code>
option.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/delete/#mongodb-dbcommand-dbcmd.delete">
<code class="leafygreen-ui-1l06pbn">
delete
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/insert/#mongodb-dbcommand-dbcmd.insert">
<code class="leafygreen-ui-1l06pbn">
insert
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update">
<code class="leafygreen-ui-1l06pbn">
update
</code>
</a>
commands that take an array of statements, the following option is also
available:
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Do not manually set
<code class="leafygreen-ui-1l06pbn">
stmtIds
</code>
. MongoDB sets the
<code class="leafygreen-ui-1l06pbn">
stmtIds
</code>
to be strictly increasing non-negative numbers.
</p>
</div>
</div>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:15%"/>
<col style="width:15%"/>
<col style="width:50%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Option
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
stmtIds
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Array of 32-bit integers
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Array of numbers that uniquely identify their respective
write operations within the write command.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Sessions Commands
<a class="headerlink leafygreen-ui-1kepx47" href="#sessions-commands" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sessions-commands">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following commands can be used to list, manage, and kill server
sessions throughout MongoDB clusters:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:15%"/>
<col style="width:50%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Commands
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Descriptions
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/endSessions/#mongodb-dbcommand-dbcmd.endSessions">
<code class="leafygreen-ui-1l06pbn">
endSessions
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Expires specified server sessions.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/killAllSessions/#mongodb-dbcommand-dbcmd.killAllSessions">
<code class="leafygreen-ui-1l06pbn">
killAllSessions
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Kills all server sessions.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/killAllSessionsByPattern/#mongodb-dbcommand-dbcmd.killAllSessionsByPattern">
<code class="leafygreen-ui-1l06pbn">
killAllSessionsByPattern
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Kills all server sessions that match the specified pattern.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/killSessions/#mongodb-dbcommand-dbcmd.killSessions">
<code class="leafygreen-ui-1l06pbn">
killSessions
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Kills specified server sessions.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/refreshSessions/#mongodb-dbcommand-dbcmd.refreshSessions">
<code class="leafygreen-ui-1l06pbn">
refreshSessions
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Refreshes idle server sessions.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/startSession/#mongodb-dbcommand-dbcmd.startSession">
<code class="leafygreen-ui-1l06pbn">
startSession
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Starts a new server session.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Sessions and Access Control
<a class="headerlink leafygreen-ui-1kepx47" href="#sessions-and-access-control" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sessions-and-access-control">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If the deployment enforces authentication/authorization, the user must
be authenticated to start a session, and only that user can use the
session.
</p>
<p class="leafygreen-ui-1kp3ins">
To use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions">
Client Sessions and Causal Consistency Guarantees
</a>
with
<code class="leafygreen-ui-1l06pbn">
$external
</code>
authentication users
(Kerberos, LDAP, or x.509 users), usernames cannot be greater
than 10k bytes.
</p>
<p class="leafygreen-ui-1kp3ins">
If the deployment does not enforce authentication/authorization, a
created session has no owner and can be used by any user on any
connection. If a user authenticates and creates a session for a
deployment that does not enforce authentication/authorization, that user
owns the session. However, any user on any connection may use the
session.
</p>
<p class="leafygreen-ui-1kp3ins">
If the deployment transitions to authentication without any downtime, any
sessions without an owner cannot be used.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxSessions">
<code class="leafygreen-ui-1l06pbn">
maxSessions
</code>
</a>
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/dataSize/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
dataSize
<a class="headerlink leafygreen-ui-1kepx47" href="#datasize" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="datasize">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self">
<span>
Command Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
dataSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.dataSize" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.dataSize">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dataSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
dataSize
</code>
</span>
</a>
command returns the size in bytes for
the specified data.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is not supported in M0, M2, and M5 clusters.
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n dataSize: <string>,\n keyPattern: <document>,\n min: <document>,\n max: <document>,\n estimate: <boolean>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dataSize</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyPattern</span>: <<span class="lg-highlight-variable lg-highlight-language">document</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <<span class="lg-highlight-variable lg-highlight-language">document</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <<span class="lg-highlight-variable lg-highlight-language">document</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">estimate</span>: <<!-- -->boolean<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command takes the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
dataSize
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The name of the target collection.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
keyPattern
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The collection's key pattern to examine.
</p>
<p class="leafygreen-ui-1kp3ins">
The collection must have an index with the corresponding pattern.
Otherwise
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dataSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
dataSize
</code>
</span>
</a>
returns an error message.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
min
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. The lower bound of the key range to be examined.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
max
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. The upper bound of the key range to be examined.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
estimate
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. When
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dataSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
dataSize
</code>
</span>
</a>
estimates the data size by
assuming that all documents in the specified range are uniformly
sized as per the collection's average object size. The collection's
average object size is obtained from the
<code class="leafygreen-ui-1l06pbn">
avgObjSize
</code>
field in
the output of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-dbcommand-dbcmd.collStats">
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
Defaults to false.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following operation runs the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dataSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
dataSize
</code>
</span>
</a>
command on the
<code class="leafygreen-ui-1l06pbn">
database.collection
</code>
collection, specifying a key pattern of
<code class="leafygreen-ui-1l06pbn">
{field: 1}
</code>
with the lower bound of the range of keys to be examined being
<code class="leafygreen-ui-1l06pbn">
{field: 10}
</code>
and the upper bound of the key to be examined being
<code class="leafygreen-ui-1l06pbn">
{field: 100}
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand({ dataSize: \"database.collection\", keyPattern: { field: 1 }, min: { field: 10 }, max: { field: 100 } })","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{ <span class="lg-highlight-attr">dataSize</span>: <span class="lg-highlight-string">"database.collection"</span>, <span class="lg-highlight-attr">keyPattern</span>: <!-- -->{ <span class="lg-highlight-attr">field</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">min</span>: <!-- -->{ <span class="lg-highlight-attr">field</span>: <span class="lg-highlight-number">10</span> }<!-- -->, <span class="lg-highlight-attr">max</span>: <!-- -->{ <span class="lg-highlight-attr">field</span>: <span class="lg-highlight-number">100</span> } })</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This returns a document with the size in bytes for all matching
documents. Replace
<code class="leafygreen-ui-1l06pbn">
database.collection
</code>
with the database and
collection from your deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
The amount of time required to return
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.dataSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
dataSize
</code>
</span>
</a>
depends on the
amount of data in the collection.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/verify-mongodb-packages/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Verify Integrity of MongoDB Packages
<a class="headerlink leafygreen-ui-1kepx47" href="#verify-integrity-of-mongodb-packages" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="verify-integrity-of-mongodb-packages">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#verify-linux-macos-packages" target="_self">
<span>
Verify Linux/macOS Packages
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#verify-windows-packages" target="_self">
<span>
Verify Windows Packages
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The MongoDB release team digitally signs all software packages to
certify that a particular MongoDB package is a valid and unaltered
MongoDB release. Before installing MongoDB, you should validate the
package using either the provided PGP signature or SHA-256 checksum.
</p>
<p class="leafygreen-ui-1kp3ins">
PGP signatures provide the strongest guarantees by checking both the
authenticity and integrity of a file to prevent tampering.
</p>
<p class="leafygreen-ui-1kp3ins">
Cryptographic checksums only validate file integrity to prevent network
transmission errors.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Verify Linux/macOS Packages
<a class="headerlink leafygreen-ui-1kepx47" href="#verify-linux-macos-packages" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="verify-linux-macos-packages">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use PGP/GPG
<a class="headerlink leafygreen-ui-1kepx47" href="#use-pgp-gpg" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-pgp-gpg">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB signs each release branch with a different PGP key. The public
key files for each release branch are available for download from the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://pgp.mongodb.com/" target="_self">
<span>
key server
</span>
</a>
in both textual
<code class="leafygreen-ui-1l06pbn">
.asc
</code>
and binary
<code class="leafygreen-ui-1l06pbn">
.pub
</code>
formats.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Download the MongoDB installation file.Download the binaries from MongoDB Download Center\nbased on your environment. You can select different platforms and versions on that page.\nClick Copy link and use the URL in the following instructions.For example, to download the 8.0.0 release for macOS through the\nshell, run this command:To download the 8.0.0 release for Linux through the\nshell, run this command:"},{"@type":"HowToStep","text":"Download the public signature file.For MacOS, run this command:For Linux, run this command:"},{"@type":"HowToStep","text":"Download then import the key file.If you have not downloaded and imported the MongoDB 8.0 public key,\nrun these commands:PGP should return this response:"},{"@type":"HowToStep","text":"Verify the MongoDB installation file.For MacOS, run this command:For Linux, run this command, using the correct filename for your platform:GPG should return this response:If the package is\nproperly signed, but you do not currently trust the signing key\nin your local trustdb, gpg will also return the following message :If you receive the following error message, confirm that you imported the correct\npublic key:"}],"name":"Use PGP/GPG","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Download the MongoDB installation file.
<a class="headerlink leafygreen-ui-1kepx47" href="#download-the-mongodb-installation-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-the-mongodb-installation-file">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Download the binaries from
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/try/download?tck=docs_server" target="_self">
<span>
MongoDB Download Center
</span>
</a>
based on your environment. You can select different platforms and versions on that page.
Click
<span class="guilabel css-h15tq0">
Copy link
</span>
and use the URL in the following instructions.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, to download the
<code class="leafygreen-ui-1l06pbn">
8.0.0
</code>
release for macOS through the
shell, run this command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To download the
<code class="leafygreen-ui-1l06pbn">
8.0.0
</code>
release for Linux through the
shell, run this command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-8.0.0.tgz\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-8.0.0.tgz</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Download the public signature file.
<a class="headerlink leafygreen-ui-1kepx47" href="#download-the-public-signature-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-the-public-signature-file">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
For MacOS, run this command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz.sig\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz.sig</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For Linux, run this command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-8.0.0.tgz.sig\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-8.0.0.tgz.sig</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Download then import the key file.
<a class="headerlink leafygreen-ui-1kepx47" href="#download-then-import-the-key-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-then-import-the-key-file">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
If you have not downloaded and imported the MongoDB 8.0 public key,
run these commands:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://pgp.mongodb.com/server-8.0.asc\ngpg --import server-8.0.asc\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://pgp.mongodb.com/server-8.0.asc</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpg --import server-8.0.asc</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
PGP should return this response:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"gpg: key 4B7C549A058F8B6B: \"MongoDB 8.0 Release Signing Key <[email protected]>\" imported\ngpg: Total number processed: 1\ngpg: imported: 1\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">gpg: key 4B7C549A058F8B6B: "MongoDB 8.0 Release Signing Key <[email protected]>" imported</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpg: Total number processed: 1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpg: imported: 1</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Verify the MongoDB installation file.
<a class="headerlink leafygreen-ui-1kepx47" href="#verify-the-mongodb-installation-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="verify-the-mongodb-installation-file">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
For MacOS, run this command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"gpg --verify mongodb-macos-x86_64-8.0.0.tgz.sig mongodb-macos-x86_64-8.0.0.tgz\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">gpg --verify mongodb-macos-x86_64-8.0.0.tgz.sig mongodb-macos-x86_64-8.0.0.tgz</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For Linux, run this command, using the correct filename for your platform:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"gpg --verify mongodb-linux-x86_64-ubuntu2204-8.0.0.tgz.sig mongodb-linux-x86_64-ubuntu2204-8.0.0.tgz\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">gpg --verify mongodb-linux-x86_64-ubuntu2204-8.0.0.tgz.sig mongodb-linux-x86_64-ubuntu2204-8.0.0.tgz</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
GPG should return this response:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"gpg: Signature made Wed Jun 5 03:17:20 2019 EDT\ngpg: using RSA key 4B7C549A058F8B6B\ngpg: Good signature from \"MongoDB 8.0 Release Signing Key <[email protected]>\" [unknown]\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">gpg: Signature made Wed Jun 5 03:17:20 2019 EDT</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpg: using RSA key 4B7C549A058F8B6B</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpg: Good signature from "MongoDB 8.0 Release Signing Key <[email protected]>" [unknown]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If the package is
properly signed, but you do not currently trust the signing key
in your local
<code class="leafygreen-ui-1l06pbn">
trustdb
</code>
,
<code class="leafygreen-ui-1l06pbn">
gpg
</code>
will also return the following message :
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"gpg: WARNING: This key is not certified with a trusted signature!\ngpg: There is no indication that the signature belongs to the owner.\nPrimary key fingerprint: E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">gpg: WARNING: This key is not certified with a trusted signature!</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpg: There is no indication that the signature belongs to the owner.</td></tr><tr class=""><td class="leafygreen-ui-7razhx">Primary key fingerprint: E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you receive the following error message, confirm that you imported the correct
public key:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"gpg: Can't check signature: public key not found\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">gpg: Can't check signature: public key not found</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use SHA-256
<a class="headerlink leafygreen-ui-1kepx47" href="#use-sha-256" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-sha-256">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Download the MongoDB installation file.Download the binaries from MongoDB Download Center\nbased on your environment. You can select different platforms and versions on that page.\nClick Copy link and use the URL in the following instructions.For example, to download the 8.0.0 release for macOS through the\nshell, type this command:To download the 8.0.0 release for Linux through the shell, run this command:"},{"@type":"HowToStep","text":"Download the SHA256 file.To download the SHA256 file for macOS through the shell, run this command\nwith the desired URL, plus .sha256:To download the SHA256 file for Linux through the shell, run this command\nwith the desired URL, plus .sha256:"},{"@type":"HowToStep","text":"Use the SHA-256 checksum to verify the MongoDB package file.Compute the checksum of the package file you downloaded:which should return the following if the checksum matched the downloaded\npackage:"}],"name":"Use SHA-256","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Download the MongoDB installation file.
<a class="headerlink leafygreen-ui-1kepx47" href="#download-the-mongodb-installation-file-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-the-mongodb-installation-file-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Download the binaries from
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/try/download?tck=docs_server" target="_self">
<span>
MongoDB Download Center
</span>
</a>
based on your environment. You can select different platforms and versions on that page.
<span class="guilabel css-h15tq0">
Click Copy
</span>
link and use the URL in the following instructions.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, to download the
<code class="leafygreen-ui-1l06pbn">
8.0.0
</code>
release for macOS through the
shell, type this command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To download the
<code class="leafygreen-ui-1l06pbn">
8.0.0
</code>
release for Linux through the shell, run this command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-6.0.8.tgz\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-6.0.8.tgz</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Download the SHA256 file.
<a class="headerlink leafygreen-ui-1kepx47" href="#download-the-sha256-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-the-sha256-file">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
To download the SHA256 file for macOS through the shell, run this command
with the desired URL, plus
<code class="leafygreen-ui-1l06pbn">
.sha256
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz.sha256\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.0.tgz.sha256</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To download the SHA256 file for Linux through the shell, run this command
with the desired URL, plus
<code class="leafygreen-ui-1l06pbn">
.sha256
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-6.0.8.tgz.sha256\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-6.0.8.tgz.sha256</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Use the SHA-256 checksum to verify the MongoDB package file.
<a class="headerlink leafygreen-ui-1kepx47" href="#use-the-sha-256-checksum-to-verify-the-mongodb-package-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-the-sha-256-checksum-to-verify-the-mongodb-package-file">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Compute the checksum of the package file you downloaded:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"shasum -c mongodb-macos-x86_64-8.0.0.tgz.sha256\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">shasum -c mongodb-macos-x86_64-8.0.0.tgz.sha256</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
which should return the following if the checksum matched the downloaded
package:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb-macos-x86_64-8.0.0.tgz: OK\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongodb-macos-x86_64-8.0.0.tgz: OK</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Verify Windows Packages
<a class="headerlink leafygreen-ui-1kepx47" href="#verify-windows-packages" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="verify-windows-packages">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following procedure verifies the MongoDB binary against its SHA256 key.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Download the installer.Download the MongoDB .msi installer. For example, to download the\nlatest version of MongoDB Community Edition, see MongoDB Community Download Center.In the Version dropdown, select\n8.0.0 (current release).In the Platform dropdown, select Windows.In the Package dropdown, select msi.Click Download and save the file to your Downloads\nfolder."},{"@type":"HowToStep","text":"Get the public signature file.Get the public signature file for your MongoDB version.For example, for the SHA256 signature of the latest version\nof MongoDB Community Edition:From https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-8.0.0-signed.msi.sha256, copy the content.Save the content to a file mongodb-windows-x86_64-8.0.0-signed.msi.sha256 in your Downloads folder."},{"@type":"HowToStep","text":"Compare the signature file to the MongoDB installer hash.To compare the signature file to the hash of the MongoDB binary,\ninvoke this Powershell script:The command outputs three lines:A SHA256 hash that you downloaded directly from MongoDB.A SHA256 hash computed from the MongoDB binary you\ndownloaded from MongoDB.A True or False result depending if the hashes match.If the hashes match, the MongoDB binary is verified."}],"name":"Verify Windows Packages","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Download the installer.
<a class="headerlink leafygreen-ui-1kepx47" href="#download-the-installer" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-the-installer">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Download the MongoDB
<code class="leafygreen-ui-1l06pbn">
.msi
</code>
installer. For example, to download the
latest version of MongoDB Community Edition, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/try/download/community?tck=docs_server" target="_self">
<span>
MongoDB Community Download Center
<!-- -->
.
</span>
</a>
</p>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In the
<span class="guilabel css-h15tq0">
Version
</span>
dropdown, select
<code class="leafygreen-ui-1l06pbn">
8.0.0 (current release)
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In the
<span class="guilabel css-h15tq0">
Platform
</span>
dropdown, select
<span class="guilabel css-h15tq0">
Windows
</span>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In the
<span class="guilabel css-h15tq0">
Package
</span>
dropdown, select
<span class="guilabel css-h15tq0">
msi
</span>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Click
<span class="guilabel css-h15tq0">
Download
</span>
and save the file to your Downloads
folder.
</p>
</li>
</ol>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Get the public signature file.
<a class="headerlink leafygreen-ui-1kepx47" href="#get-the-public-signature-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="get-the-public-signature-file">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Get the public signature file for your MongoDB version.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, for the SHA256 signature of the latest version
of MongoDB Community Edition:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
From
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-8.0.0-signed.msi.sha256" rel="noopener noreferrer">
<span>
https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-8.0.0-signed.msi.sha256
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
, copy the content.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Save the content to a file
<code class="leafygreen-ui-1l06pbn">
mongodb-windows-x86_64-8.0.0-signed.msi.sha256
</code>
in your Downloads folder.
</p>
</li>
</ol>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Compare the signature file to the MongoDB installer hash.
<a class="headerlink leafygreen-ui-1kepx47" href="#compare-the-signature-file-to-the-mongodb-installer-hash" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compare-the-signature-file-to-the-mongodb-installer-hash">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To compare the signature file to the hash of the MongoDB binary,
invoke this Powershell script:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"$sigHash = (Get-Content $Env:HomePath\\Downloads\\mongodb-windows-x86_64-8.0.0-signed.msi.sha256 | Out-String).SubString(0,64).ToUpper(); `\n$fileHash = (Get-FileHash $Env:HomePath\\Downloads\\mongodb-windows-x86_64-8.0.0-signed.msi).Hash.Trim(); `\necho $sigHash; echo $fileHash; `\n$sigHash -eq $fileHash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">$sigHash = (Get-Content $Env:HomePath\Downloads\mongodb-windows-x86_64-8.0.0-signed.msi.sha256 | Out-String).SubString(0,64).ToUpper(); `</td></tr><tr class=""><td class="leafygreen-ui-7razhx">$fileHash = (Get-FileHash $Env:HomePath\Downloads\mongodb-windows-x86_64-8.0.0-signed.msi).Hash.Trim(); `</td></tr><tr class=""><td class="leafygreen-ui-7razhx">echo $sigHash; echo $fileHash; `</td></tr><tr class=""><td class="leafygreen-ui-7razhx">$sigHash -eq $fileHash</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"C777DF7816BB8C9A760FDEA782113949408B6F39D72BE29A2551FA51E2FE0473\nC777DF7816BB8C9A760FDEA782113949408B6F39D72BE29A2551FA51E2FE0473\nTrue"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">C777DF7816BB8C9A760FDEA782113949408B6F39D72BE29A2551FA51E2FE0473</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">C777DF7816BB8C9A760FDEA782113949408B6F39D72BE29A2551FA51E2FE0473</td></tr><tr class=""><td class="leafygreen-ui-7razhx">True</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The command outputs three lines:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A
<code class="leafygreen-ui-1l06pbn">
SHA256
</code>
hash that you downloaded directly from MongoDB.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A
<code class="leafygreen-ui-1l06pbn">
SHA256
</code>
hash computed from the MongoDB binary you
downloaded from MongoDB.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A
<code class="leafygreen-ui-1l06pbn">
True
</code>
or
<code class="leafygreen-ui-1l06pbn">
False
</code>
result depending if the hashes match.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If the hashes match, the MongoDB binary is verified.
</p>
</section>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/storage-engines/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Storage Engines for Self-Managed Deployments
<a class="headerlink leafygreen-ui-1kepx47" href="#storage-engines-for-self-managed-deployments" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="storage-engines-for-self-managed-deployments">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-storage-engine">
storage engine
</a>
is the component of the database that is
responsible for managing how data is stored, both in memory and on disk.
MongoDB supports multiple storage engines, as different engines perform
better for specific workloads. Choosing the appropriate storage engine
for your use case can significantly impact the performance of your
applications.
</p>
<dl>
<dt>
➤
<!-- -->
WiredTiger Storage Engine (
<em>
Default
</em>
)
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
is the default storage engine and is
recommended for new deployments. WiredTiger provides a document-level
concurrency model, checkpointing, and compression, among other features.
</p>
<p class="leafygreen-ui-1kp3ins">
In MongoDB Enterprise, WiredTiger also supports
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/">
Encryption at Rest
</a>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-encrypted-storage-engine">
Encrypted Storage Engine
<!-- -->
.
</a>
</p>
</dd>
<dt>
➤
<!-- -->
In-Memory Storage Engine
</dt>
<dd class="css-1ufxuu7">
An
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
In-Memory storage engine
</a>
is available
in MongoDB Enterprise. Rather than storing documents on-disk, it
retains them in-memory for more predictable data latencies.
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/core/read-preference/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Read Preference
<a class="headerlink leafygreen-ui-1kepx47" href="#read-preference" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-preference">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#read-preference-modes" target="_self">
<span>
Read Preference Modes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#read-preference-modes-1" target="_self">
<span>
Read Preference Modes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#configure-read-preference" target="_self">
<span>
Configure Read Preference
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#read-preference-and-transactions" target="_self">
<span>
Read Preference and Transactions
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-considerations" target="_self">
<span>
Additional Considerations
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Read preference describes how MongoDB clients route read operations to
the members of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
<!-- -->
.
</a>
</p>
<div class="css-q7r6u4 ej97su30">
<div role="button" tabindex="-1">
<img alt="Read operations to a replica set. Default read preference routes the read to the primary. Read preference of ``nearest`` routes the read to the nearest member." class="leafygreen-ui-1qnf57e" height="480" src="/docs/manual/images/replica-set-read-preference.bakedsvg.svg" style="--border-color:#C1C7C6" width="800"/>
<div class="css-19pi7x2 ej97su31" style="--color:#444">
click to enlarge
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
By default, an application directs its read operations to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
member in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
(i.e. read preference
mode "primary"). But, clients can specify a read preference to send
read operations to secondaries.
</p>
<p class="leafygreen-ui-1kp3ins">
Read preference consists of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-read-pref-modes-summary" target="_self">
<span>
read preference mode
</span>
</a>
and optionally, a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
tag set list
</a>
, and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
maxStalenessSeconds
</a>
option.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-read-pref-summary">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-read-pref-modes-summary">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Read Preference Modes
<a class="headerlink leafygreen-ui-1kepx47" href="#read-preference-modes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-preference-modes">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following table summarizes the read preference modes:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:50%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Read Preference Mode
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Default mode. All operations read from the current replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
Distributed transactions
</a>
that contain
read operations must use read preference
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
. All
operations in a given transaction must route to the same member.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primaryPreferred" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primaryPreferred
</code>
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
In most situations, operations read from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
but
if it is unavailable, operations read from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-secondary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
All operations read from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members of the
replica set.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-secondaryPreferred" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
secondaryPreferred
</code>
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Operations typically read data from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members of the
replica set. If the replica set has only one single
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
member and no other members, operations read data from the primary
member.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-nearest" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Operations read from a random eligible
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
member, irrespective of whether that member is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
, based on a specified latency threshold.
The operation considers the following when calculating latency:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string-options/#mongodb-urioption-urioption.localThresholdMS">
<code class="leafygreen-ui-1l06pbn">
localThresholdMS
</code>
</a>
connection string option
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
maxStalenessSeconds
</a>
read preference
option
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Any specified
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-replica-set-tag-sets/">
tag set lists
</a>
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For detailed description of the read preference modes, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replica-set-read-preference-modes" target="_self">
<span>
Read Preference Modes
<!-- -->
.
</span>
</a>
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
Read Preference Tag Set Lists
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
Read Preference
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
All read preference modes except
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
may return
stale data because
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondaries
</a>
replicate
operations from the primary in an asynchronous process.
<a class="footnote-reference header-buffer" href="#footnote-edge-cases-2-primaries" id="ref-edge-cases-2-primaries-id1">
[
<!-- -->
1
<!-- -->
]
</a>
Ensure that your application can
tolerate stale data if you choose to use a non-
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
mode.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Read preference does not affect the visibility of data;
i.e. clients can see the results of writes before they are
acknowledged or have propagated to a majority of replica set
members. For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/">
Read Isolation, Consistency, and Recency
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Read preference does not affect
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency">
causal consistency
</a>
. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions">
causal consistency guarantees
</a>
provided by
causally consistent sessions for read operations with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
read concern and write operations with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
write concern hold across all members
of the MongoDB deployment.
</p>
</li>
</ul>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Secondary Reads in a Sharded Cluster with Migrations Can Miss Documents
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Long-running secondary reads in a sharded cluster can miss documents
if migrations are occurring.
</p>
<p class="leafygreen-ui-1kp3ins">
Before deleting a chunk during chunk migration, MongoDB waits for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.orphanCleanupDelaySecs">
<code class="leafygreen-ui-1l06pbn">
orphanCleanupDelaySecs
</code>
</a>
, or for in-progress queries
involving the chunk to complete on the shard primary, whichever is
longer. Queries that were initially run on a node that was primary,
but continue after the node has stepped down to a secondary, will be
treated as if they were initially executed on a secondary. That is,
the server only waits for
<code class="leafygreen-ui-1l06pbn">
orphanDelayCleanupSecs
</code>
if there are no
queries targeting the chunk on the current primary.
</p>
<p class="leafygreen-ui-1kp3ins">
Queries that target the chunk and are run on secondaries may miss
documents if these queries take longer than
<code class="leafygreen-ui-1l06pbn">
orphanCleanupDelaySecs
</code>
.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-read-preference-modes">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Read Preference Modes
<a class="headerlink leafygreen-ui-1kepx47" href="#read-preference-modes-1" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-preference-modes-1">
</div>
</a>
</h2>
<dl class="readmode">
<dt>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-readmode-primary" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-readmode-primary">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
All read operations use only the current replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
.
<a class="footnote-reference header-buffer" href="#footnote-edge-cases-2-primaries" id="ref-edge-cases-2-primaries-id2">
[
<!-- -->
1
<!-- -->
]
</a>
This is the default read
mode. If the primary is unavailable, read operations produce an
error or throw an exception.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
read preference mode is not compatible with
read preference modes that use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
tag set lists
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
maxStalenessSeconds
</a>
.
If you specify tag set lists or a
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value
with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
, the driver will produce an error.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
Distributed transactions
</a>
that contain
read operations must use read preference
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
. All
operations in a given transaction must route to the same member.
</p>
</dd>
</dl>
<dl class="readmode">
<dt>
<code class="leafygreen-ui-1l06pbn">
primaryPreferred
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-readmode-primaryPreferred" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-readmode-primaryPreferred">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
In most situations, operations read from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
member
of the set. However, if the primary is unavailable, as is the case
during
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-failover">
failover
</a>
situations, operations read from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members that satisfy the read preference's
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
and
tag set lists.
</p>
<p class="leafygreen-ui-1kp3ins">
When the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primaryPreferred" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primaryPreferred
</code>
</span>
</a>
read preference includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
maxStalenessSeconds value
</a>
and there is no primary from which to read,
the client estimates how stale each
secondary is by comparing the secondary's last write
to that of the secondary with the most recent write. The client then directs the read operation to a
secondary whose estimated lag is less than or equal to
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
When the read preference includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
tag set list (an array of tag
sets)
</a>
and there is no primary from which to read,
the client attempts to find secondary members with matching tags
(trying the tag sets in order until a match is found). If
matching secondaries are found, the client selects a
random secondary from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-nearest">
nearest group
</a>
of matching
secondaries. If no secondaries have matching tags, the read operation produces an error.
</p>
<p class="leafygreen-ui-1kp3ins">
When the read preference includes a
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value
<strong>
and
</strong>
a tag set list, the client filters by staleness first and
then by the specified tags.
</p>
<p class="leafygreen-ui-1kp3ins">
Read operations using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primaryPreferred" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primaryPreferred
</code>
</span>
</a>
mode may return stale data. Use the
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
option to avoid reading from secondaries
that the client estimates are overly stale.
</p>
</dd>
</dl>
<dl class="readmode">
<dt>
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-readmode-secondary" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-readmode-secondary">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Operations read
<em>
only
</em>
from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members of the set.
If no secondaries are available, then this read operation produces an
error or exception.
</p>
<p class="leafygreen-ui-1kp3ins">
Most replica sets have at least one secondary, but there are
situations where there may be no available secondary. For example, a
replica set with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
, a secondary, and an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-arbiter">
arbiter
</a>
may not have any secondaries if a member is in
recovering state or unavailable.
</p>
<p class="leafygreen-ui-1kp3ins">
When the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-secondary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</span>
</a>
read preference includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
maxStalenessSeconds value
</a>
,
the client estimates how stale each
secondary is by comparing the secondary's last write
to that of the primary. The client then directs the read operation to a
secondary whose estimated lag is less than or equal to
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
.
If there is no primary, the client uses the secondary with the most
recent write for the comparison.
</p>
<p class="leafygreen-ui-1kp3ins">
When the read preference includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
tag set list (an array of tag
sets)
</a>
,
the client attempts to find secondary members with matching tags
(trying the tag sets in order until a match is found). If
matching secondaries are found, the client selects a
random secondary from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-nearest">
nearest group
</a>
of matching
secondaries. If no secondaries have matching tags, the read operation produces an error.
</p>
<p class="leafygreen-ui-1kp3ins">
When the read preference includes a
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value
<strong>
and
</strong>
a tag set list, the client filters by staleness first and
then by the specified tags.
</p>
<p class="leafygreen-ui-1kp3ins">
Read operations using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-secondary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</span>
</a>
mode may return stale data. Use the
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
option to avoid reading from secondaries
that the client estimates are overly stale.
</p>
</dd>
</dl>
<dl class="readmode">
<dt>
<code class="leafygreen-ui-1l06pbn">
secondaryPreferred
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-readmode-secondaryPreferred" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-readmode-secondaryPreferred">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Operations typically read data from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members of the
replica set. If the replica set has only one single
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
member and no other members, operations read data from the primary
member.
</p>
<p class="leafygreen-ui-1kp3ins">
When the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-secondaryPreferred" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
secondaryPreferred
</code>
</span>
</a>
read preference includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
maxStalenessSeconds value
</a>
,
the client estimates how stale each
secondary is by comparing the secondary's last write
to that of the primary. The client then directs the read operation to a
secondary whose estimated lag is less than or equal to
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
.
If there is no primary, the client uses the secondary with the most
recent write for the comparison. If there are no secondaries with
estimated lag less than or equal to
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
, the
client directs the read operation to the replica set's primary.
</p>
<p class="leafygreen-ui-1kp3ins">
When the read preference includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
tag set list (an array of tag
sets)
</a>
,
the client attempts to find secondary members with matching tags
(trying the tag sets in order until a match is found). If
matching secondaries are found, the client selects a
random secondary from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-nearest">
nearest group
</a>
of matching
secondaries. If no secondaries have matching tags, the client ignores tags and reads from the primary.
</p>
<p class="leafygreen-ui-1kp3ins">
When the read preference includes a
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value
<strong>
and
</strong>
a tag set list, the client filters by staleness first and
then by the specified tags.
</p>
<p class="leafygreen-ui-1kp3ins">
Read operations using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-secondaryPreferred" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
secondaryPreferred
</code>
</span>
</a>
mode may return stale data. Use the
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
option to avoid reading from secondaries
that the client estimates are overly stale.
</p>
</dd>
</dl>
<dl class="readmode">
<dt>
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-readmode-nearest" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-readmode-nearest">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The driver reads from a member whose network latency falls within
the acceptable latency window. Reads in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-nearest" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
</span>
</a>
mode
do not consider whether a member is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
when routing read operations: primaries and
secondaries are treated equivalently.
</p>
<p class="leafygreen-ui-1kp3ins">
Set this mode to minimize the effect of network latency
on read operations without preference for current or stale data.
</p>
<p class="leafygreen-ui-1kp3ins">
When the read preference includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-staleness/#std-label-replica-set-read-preference-max-staleness">
maxStalenessSeconds value
</a>
, the client estimates
how stale each secondary is by comparing the secondary's last write
to that of the primary, if available, or to the secondary with the
most recent write if there is no primary. The client will then
filter out any secondary whose estimated lag is greater than
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
and randomly direct the read to a remaining
member (primary or secondary) whose network latency falls within the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-nearest">
acceptable latency window
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If you specify a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
tag set list
</a>
, the client attempts to
find a replica set member that matches the specified tag set lists and
directs reads to an arbitrary member from among the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-nearest">
nearest
group
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
When the read preference includes a
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value
<strong>
and
</strong>
a tag set list, the client filters by staleness first and
then by the specified tags. From the remaining
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances, the client then
randomly directs the read to an instance that falls within the
acceptable latency window. The read preference
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-nearest">
member
selection
</a>
documentation describes the process in detail.
</p>
<p class="leafygreen-ui-1kp3ins">
Read operations using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-nearest" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
</span>
</a>
mode may return stale data. Use the
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
option to avoid reading from secondaries
that the client estimates are overly stale.
</p>
</dd>
</dl>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To learn about use cases for specific read preference settings,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-use-cases/#std-label-read-preference-use-cases">
Read Preference Use Cases
<!-- -->
.
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-read-preference-configure">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Configure Read Preference
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-read-preference" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configure-read-preference">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When using a MongoDB driver, you can specify the read preference using
the driver's read preference API. See the driver
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
API
documentation
</span>
</a>
. You can also set the read preference when
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string-options/#std-label-connections-read-preference">
connecting to the replica set or sharded cluster
</a>
. For an example, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string-options/#std-label-connections-read-preference">
connection
string
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For a given read preference, the MongoDB drivers use the same
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-member-selection">
member selection logic
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
When using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.readPref/#mongodb-method-cursor.readPref">
<code class="leafygreen-ui-1l06pbn">
cursor.readPref()
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo.setReadPref/#mongodb-method-Mongo.setReadPref">
<code class="leafygreen-ui-1l06pbn">
Mongo.setReadPref()
</code>
.
</a>
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Read Preference and Transactions
<a class="headerlink leafygreen-ui-1kepx47" href="#read-preference-and-transactions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-preference-and-transactions">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
Distributed transactions
</a>
that contain
read operations must use read preference
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
. All
operations in a given transaction must route to the same member.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-considerations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="additional-considerations">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider the following points when using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
stages in an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation pipeline
<!-- -->
:
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, pipelines with a
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
stage can run on
replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
nodes if all the nodes in the cluster
have the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
featureCompatibilityVersion
</a>
set to
<code class="leafygreen-ui-1l06pbn">
5.0
</code>
or higher and the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-read-preference" target="_self">
<span>
read preference
</span>
</a>
allows secondary reads.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
and
<code class="leafygreen-ui-1l06pbn">
$out
</code>
stages run on secondary nodes, but write
operations are sent to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
node.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Not all driver versions support
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
operations sent to
the secondary nodes. For details, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver
</span>
</a>
documentation.
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In earlier MongoDB versions, pipelines with
<code class="leafygreen-ui-1l06pbn">
$out
</code>
or
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
stages always run on the primary node and read preference isn't
considered.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
mapReduce
</code>
</a>
operations, only "inline"
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
mapReduce
</code>
</a>
operations that do not write data support read
preference. Otherwise,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
mapReduce
</code>
</a>
operations run on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
member.
</p>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-edge-cases-2-primaries" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<!-- -->
1
<!-- -->
]
</td>
<td class="leafygreen-ui-17r2xs0">
<em>
(
<a href="#ref-edge-cases-2-primaries-id1">
1
</a>
,
<a href="#ref-edge-cases-2-primaries-id2">
2
</a>
)
</em>
<!-- -->
In
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-use-cases/#std-label-edge-cases">
some circumstances
</a>
, two nodes in a replica set
may
<em>
transiently
</em>
believe that they are the primary, but at most, one
of them will be able to complete writes with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
{ w:
"majority" }
</code>
</a>
write concern. The node that can complete
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
{ w: "majority" }
</code>
</a>
writes is the current
primary, and the other node is a former primary that has not yet
recognized its demotion, typically due to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-network-partition">
network partition
</a>
.
When this occurs, clients that connect to the former primary may
observe stale data despite having requested read preference
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-readmode-primary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</span>
</a>
, and new writes to the former primary will
eventually roll back.
</td>
</tr>
</tbody>
</table>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2dsphere/query/geojson-bound-by-polygon/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Query for Locations Bound by a Polygon
<a class="headerlink leafygreen-ui-1kepx47" href="#query-for-locations-bound-by-a-polygon" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="query-for-locations-bound-by-a-polygon">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#about-this-task" target="_self">
<span>
About this Task
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#before-you-begin" target="_self">
<span>
Before You Begin
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#procedure" target="_self">
<span>
Procedure
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
You can query for location data within the perimeter of a specified
polygon.
</p>
<p class="leafygreen-ui-1kp3ins">
To query for location data within a perimeter, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
<code class="leafygreen-ui-1l06pbn">
$geoWithin
</code>
</a>
operator and specify the coordinates of the
polygon's vertices:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.<collection>.find( {\n <location> : {\n $geoWithin : {\n $geometry : {\n type : \"Polygon\",\n coordinates : [ <coordinates> ]\n }\n }\n }\n } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<!-- --><<!-- -->collection<!-- -->><!-- -->.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- --><location field> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> $geoWithin : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> $geometry : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> type : "Polygon",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> coordinates : [ <coordinates> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
About this Task
<a class="headerlink leafygreen-ui-1kepx47" href="#about-this-task" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="about-this-task">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The values in the field you query with the
<code class="leafygreen-ui-1l06pbn">
$geoWithin
</code>
operator
must be in GeoJSON format.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When you specify longitude and latitude coordinates, list the
<strong>
longitude
</strong>
first, and then
<strong>
latitude
</strong>
.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Valid longitude values are between
<code class="leafygreen-ui-1l06pbn">
-180
</code>
and
<code class="leafygreen-ui-1l06pbn">
180
</code>
, both
inclusive.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Valid latitude values are between
<code class="leafygreen-ui-1l06pbn">
-90
</code>
and
<code class="leafygreen-ui-1l06pbn">
90
</code>
, both
inclusive.
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When you specify Polygon
<code class="leafygreen-ui-1l06pbn">
coordinates
</code>
, the first and last
coordinates in the array must be the same. This closes the bounds of
the polygon.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$geoWithin
</code>
does not require a geospatial index. However, a
geospatial index improves query performance. Only the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index">
2dsphere
</a>
geospatial index supports
<code class="leafygreen-ui-1l06pbn">
$geoWithin
</code>
. For
more information see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/create/#std-label-create-2dsphere-index">
Create a 2dsphere Index
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Before You Begin
<a class="headerlink leafygreen-ui-1kepx47" href="#before-you-begin" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="before-you-begin">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Create a
<code class="leafygreen-ui-1l06pbn">
places
</code>
collection that contains these documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.places.insertMany( [\n {\n loc: { type: \"Point\", coordinates: [ -73.97, 40.77 ] },\n name: \"Central Park\",\n category : \"Park\"\n },\n {\n loc: { type: \"Point\", coordinates: [ -73.88, 40.78 ] },\n name: \"La Guardia Airport\",\n category: \"Airport\"\n },\n {\n loc: { type: \"Point\", coordinates: [ -1.83, 51.18 ] },\n name: \"Stonehenge\",\n category : \"Monument\"\n }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">places</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">loc</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.97</span>, <span class="lg-highlight-number">40.77</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Central Park"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->category <!-- -->: <span class="lg-highlight-string">"Park"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">loc</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.88</span>, <span class="lg-highlight-number">40.78</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"La Guardia Airport"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"Airport"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">loc</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">1.83</span>, <span class="lg-highlight-number">51.18</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Stonehenge"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->category <!-- -->: <span class="lg-highlight-string">"Monument"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Procedure
<a class="headerlink leafygreen-ui-1kepx47" href="#procedure" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="procedure">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Use
<code class="leafygreen-ui-1l06pbn">
$geoWithin
</code>
to query the collection. The following
<code class="leafygreen-ui-1l06pbn">
$geoWithin
</code>
query specifies a polygon with four vertices (a rectangle) and returns
points within that polygon:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.places.find( {\n loc: {\n $geoWithin: {\n $geometry: {\n type: \"Polygon\",\n coordinates: [ [\n [ -73.95, 40.80 ],\n [ -73.94, 40.79 ],\n [ -73.97, 40.76 ],\n [ -73.98, 40.76 ],\n [ -73.95, 40.80 ]\n ] ]\n }\n }\n }\n} )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">places</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">loc</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$geoWithin</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$geometry</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Polygon"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.95</span>, <span class="lg-highlight-number">40.80</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.94</span>, <span class="lg-highlight-number">40.79</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.97</span>, <span class="lg-highlight-number">40.76</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.98</span>, <span class="lg-highlight-number">40.76</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.95</span>, <span class="lg-highlight-number">40.80</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ] ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: ObjectId(\"63a4a8d67348ebdcd0a061f0\"),\n loc: { type: 'Point', coordinates: [ -73.97, 40.77 ] },\n name: 'Central Park',\n category: 'Park'\n }\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"63a4a8d67348ebdcd0a061f0"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">loc</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'Point'</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.97</span>, <span class="lg-highlight-number">40.77</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'Central Park'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">'Park'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
<code class="leafygreen-ui-1l06pbn">
$geoWithin
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geojson-polygon">
<code class="leafygreen-ui-1l06pbn">
Polygon
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/restrictions/#std-label-geospatial-restrictions">
Geospatial Index Restrictions
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/logRotate/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
logRotate
<a class="headerlink leafygreen-ui-1kepx47" href="#logrotate" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="logrotate">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self">
<span>
Command Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#limitations" target="_self">
<span>
Limitations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.logRotate" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.logRotate">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.logRotate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</span>
</a>
command is an administrative command that
allows you to rotate the MongoDB server log and/or audit log to
prevent a single logfile from consuming too much disk space.
</p>
<p class="leafygreen-ui-1kp3ins">
You must issue the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.logRotate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</span>
</a>
command against the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-admin-database">
admin database
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is not supported in M0, M2, M5, and M10+ clusters.
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n logRotate: <integer>,\n comment: <string>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">logRotate</span>: <!-- --><integer or string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> comment: <string></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command takes the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer or string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The log or logs to rotate, according to the following:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
-- Rotates both the server and audit logs
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
"server"
</code>
-- Rotates only the server log
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
"audit"
</code>
-- Rotates only the audit log
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
comment
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<em>
Optional.
</em>
A message logged by the server to the log file and
audit file at time of log rotation.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
You may also rotate the logs by sending a
<code class="leafygreen-ui-1l06pbn">
SIGUSR1
</code>
signal to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, if a running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance has a
process ID (PID) of
<code class="leafygreen-ui-1l06pbn">
2200
</code>
, the following command rotates the log
file for that instance on Linux:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"kill -SIGUSR1 2200","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">kill</span> -SIGUSR1 2200</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Limitations
<a class="headerlink leafygreen-ui-1kepx47" href="#limitations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="limitations">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance needs to be running with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--logpath">
<code class="leafygreen-ui-1l06pbn">
--logpath [file]
</code>
</a>
option in order to use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.logRotate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing">
Auditing
</a>
must be enabled to rotate the audit log.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-systemLog.logRotate">
<code class="leafygreen-ui-1l06pbn">
systemLog.logRotate
</code>
</a>
setting or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--logRotate">
<code class="leafygreen-ui-1l06pbn">
--logRotate
</code>
</a>
option specify
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.logRotate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</span>
</a>
's behavior.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-systemLog.logRotate">
<code class="leafygreen-ui-1l06pbn">
systemLog.logRotate
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--logRotate">
<code class="leafygreen-ui-1l06pbn">
--logRotate
</code>
</a>
are set to
<code class="leafygreen-ui-1l06pbn">
rename
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.logRotate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</span>
</a>
renames the existing log file by appending the current timestamp to the
filename. The appended timestamp has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"<yyyy>-<mm>-<dd>T<hh>-<mm>-<ss></dd>"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><YYYY>-<mm>-<DD>T<HH>-<MM>-<SS></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Then
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.logRotate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</span>
</a>
creates a new log file with the same
name as originally specified by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-systemLog.path">
<code class="leafygreen-ui-1l06pbn">
systemLog.path
</code>
</a>
setting to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-systemLog.logRotate">
<code class="leafygreen-ui-1l06pbn">
systemLog.logRotate
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--logRotate">
<code class="leafygreen-ui-1l06pbn">
--logRotate
</code>
</a>
are set to
<code class="leafygreen-ui-1l06pbn">
reopen
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.logRotate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</span>
</a>
follows the typical Linux/Unix behavior, and simply closes the log file
then reopens a log file with the same name. With
<code class="leafygreen-ui-1l06pbn">
reopen
</code>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
expects that another process renames the file
prior to the rotation, and that the reopen results in the creation of a
new file.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following example rotates both the server log and the audit log:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { logRotate: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">logRotate</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example rotates only the audit log, and provides a custom
message to the log file at time of rotation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { logRotate: \"audit\", comment: \"Rotating audit log\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">logRotate</span>: <span class="lg-highlight-string">"audit"</span>, <span class="lg-highlight-attr">comment</span>: <span class="lg-highlight-string">"Rotating audit log"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/indexes/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="indexes">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#use-cases" target="_self">
<span>
Use Cases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#get-started" target="_self">
<span>
Get Started
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#details" target="_self">
<span>
Details
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Indexes support efficient execution of queries in MongoDB. Without
indexes, MongoDB must scan every document in a collection to return
query results. If an appropriate index exists for a query, MongoDB uses
the index to limit the number of documents it must scan.
</p>
<p class="leafygreen-ui-1kp3ins">
Although indexes improve query performance, adding an index has negative
performance impact for write operations. For collections with a high
write-to-read ratio, indexes are expensive because each insert must also
update any indexes.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Use Cases
<a class="headerlink leafygreen-ui-1kepx47" href="#use-cases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-cases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If your application is repeatedly running queries on the same fields,
you can create an index on those fields to improve performance. For
example, consider the following scenarios:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:10%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Scenario
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Index Type
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A human resources department often needs to look up employees by
employee ID. You can create an index on the employee ID field to
improve query performance.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-single/#std-label-indexes-single-field">
Single Field Index
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A salesperson often needs to look up client information by
location. Location is stored in an embedded object with fields
like
<code class="leafygreen-ui-1l06pbn">
state
</code>
,
<code class="leafygreen-ui-1l06pbn">
city
</code>
, and
<code class="leafygreen-ui-1l06pbn">
zipcode
</code>
. You can create an
index on the
<code class="leafygreen-ui-1l06pbn">
location
</code>
object to improve performance for
queries on that object.
</p>
<p class="leafygreen-ui-1kp3ins">
When you create an index on an embedded document, only queries that
specify the entire embedded document use the index. Queries on a
specific field within the document do not use the index.
</p>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-single/#std-label-indexes-single-field">
Single Field Index
</a>
on an embedded
document
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A grocery store manager often needs to look up inventory items by
name and quantity to determine which items are low stock. You can
create a single index on both the
<code class="leafygreen-ui-1l06pbn">
item
</code>
and
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
fields to improve query performance.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-index-type-compound">
Compound Index
</a>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Get Started
<a class="headerlink leafygreen-ui-1kepx47" href="#get-started" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="get-started">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can create and manage indexes in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
, with a driver
method, or with the MongoDB Shell. MongoDB Atlas is the fully
managed service for MongoDB deployments in the cloud.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create and Manage Indexes in MongoDB Atlas
<a class="headerlink leafygreen-ui-1kepx47" href="#create-and-manage-indexes-in-mongodb-atlas" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-and-manage-indexes-in-mongodb-atlas">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For deployments hosted in MongoDB Atlas, you can create
and manage indexes with the MongoDB Atlas UI or the Atlas CLI. MongoDB Atlas
also includes a Performance Advisor that recommends indexes to improve
slow queries, ranks suggested indexes by impact, and recommends which
indexes to drop.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn how to create and manage indexes the MongoDB Atlas UI or the Atlas
CLI, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/indexes/" target="_self">
<span>
Create, View, Drop, and Hide Indexes
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about the MongoDB Atlas Performance Advisor, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/performance-advisor/" target="_self">
<span>
Monitor and Improve Slow Queries
<!-- -->
.
</span>
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create and Manage Indexes with a Driver Method or the MongoDB Shell
<a class="headerlink leafygreen-ui-1kepx47" href="#create-and-manage-indexes-with-a-driver-method-or-the-mongodb-shell" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-and-manage-indexes-with-a-driver-method-or-the-mongodb-shell">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can create and manage indexes with a driver method or the MongoDB
Shell. To learn more, see the following resources:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/create-index/#std-label-manual-create-an-index">
Create an Index
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/create-compound-index/#std-label-index-create-compound">
Create a Compound Index
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-multikey/create-multikey-index-basic/#std-label-index-create-multikey-basic">
Create an Index on an Array Field
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-geospatial/#std-label-geospatial-index">
Create an Index to Support Geospatial Queries
</a>
</p>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Details
<a class="headerlink leafygreen-ui-1kepx47" href="#details" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="details">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Indexes are special data structures that store a small portion of the
collection's data set in an easy-to-traverse form. MongoDB indexes use a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/B-tree" rel="noopener noreferrer">
<span>
B-tree
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
data structure.
</p>
<p class="leafygreen-ui-1kp3ins">
The index stores the value of a specific field or set of fields, ordered
by the value of the field. The ordering of the index entries supports
efficient equality matches and range-based query operations. In
addition, MongoDB can return sorted results using the ordering in the
index.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Restrictions
<a class="headerlink leafygreen-ui-1kepx47" href="#restrictions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restrictions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Certain restrictions apply to indexes, such as the length of the index
keys or the number of indexes per collection. For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#std-label-index-limitations">
Index Limitations
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-index-type-id">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Default Index
<a class="headerlink leafygreen-ui-1kepx47" href="#default-index" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="default-index">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB creates a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
unique index
</a>
on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/document/#std-label-document-id-field">
_id
</a>
field during the creation of a
collection. The
<code class="leafygreen-ui-1l06pbn">
_id
</code>
index prevents clients from inserting two
documents with the same value for the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field. You cannot drop
this index.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
In
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded clusters
</a>
, if you do
<em>
not
</em>
use
the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field as the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
, then your application
<strong>
must
</strong>
ensure the uniqueness of the values in the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field.
You can do this by using a field with an auto-generated
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ObjectId">
ObjectId
<!-- -->
.
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-index-names">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Names
<a class="headerlink leafygreen-ui-1kepx47" href="#index-names" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="index-names">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The default name for an index is the concatenation of the indexed keys
and each key's direction in the index (
<code class="leafygreen-ui-1l06pbn">
1
</code>
or
<code class="leafygreen-ui-1l06pbn">
-1
</code>
) using underscores
as a separator. For example, an index created on
<code class="leafygreen-ui-1l06pbn">
{ item : 1, quantity:
-1 }
</code>
has the name
<code class="leafygreen-ui-1l06pbn">
item_1_quantity_-1
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot rename an index once created. Instead, you must
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/drop-index/#std-label-drop-an-index">
drop
</a>
and recreate the index with a new name.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn how to specify the name for an index, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/create-index/specify-index-name/#std-label-specify-index-name">
Specify an Index Name
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Build Performance
<a class="headerlink leafygreen-ui-1kepx47" href="#index-build-performance" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="index-build-performance">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Applications may encounter reduced performance during index builds,
including limited read/write access to the collection. For more
information on the index build process, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations">
Index Builds on Populated Collections
</a>
,
including the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations-replicated-build">
Index Builds in Replicated Environments
</a>
section.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB provides a number of different index types to support specific
types of data and queries. To learn more, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/#std-label-index-types">
Index Types
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To learn what properties and behaviors you can specify in your index,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-properties/#std-label-index-properties">
Index Properties
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To understand considerations you may need to make when you create an
index, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/applications/indexes/#std-label-manual-indexing-strategies">
Indexing Strategies
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To learn about the performance impact of indexes, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/data-model-operations/#std-label-data-model-indexes">
Operational Factors and Data Models
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To learn about query settings and indexes, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setQuerySettings/#mongodb-dbcommand-dbcmd.setQuerySettings">
<code class="leafygreen-ui-1l06pbn">
setQuerySettings
</code>
.
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/crud/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
MongoDB CRUD Concepts
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-crud-concepts" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-crud-concepts">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
This section contains information on additional concepts related to
CRUD operations in MongoDB.
</p>
<dl>
<dt>
Atomicity, consistency, and distributed operations
</dt>
<dd class="css-1ufxuu7">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/write-operations-atomicity/">
Atomicity and Transactions
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/">
Read Isolation, Consistency, and Recency
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/distributed-queries/">
Distributed Queries
</a>
</p>
</li>
</ul>
</dd>
<dt>
Query Plan, Performance, Analysis, and Query Shape
</dt>
<dd class="css-1ufxuu7">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/">
Query Plans
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-optimization/">
Query Optimization
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/write-performance/">
Write Operation Performance
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-shapes/">
Query Shapes
</a>
</p>
</li>
</ul>
</dd>
<dt>
Miscellaneous
</dt>
<dd class="css-1ufxuu7">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/tailable-cursors/">
Tailable Cursors
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/dot-dollar-considerations/">
Field Names with Periods and Dollar Signs
</a>
</p>
</li>
</ul>
</dd>
</dl>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
Transactions
</a>
</p>
</div>
</div>
</section>
|
https://www.mongodb.com/docs/manual/data-center-awareness/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Data Center Awareness
<a class="headerlink leafygreen-ui-1kepx47" href="#data-center-awareness" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="data-center-awareness">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#further-reading" target="_self">
<span>
Further Reading
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB provides a number of features that allow application
developers and database administrators to customize the behavior of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
deployment so that
MongoDB may be
<em>
more
</em>
"data center aware," or allow operational
and location-based separation.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB also supports workload isolation based on functional parameters, to ensure
that certain
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances are only used for reporting workloads
or that certain high-frequency portions of a sharded collection only exist on
specific shards.
</p>
<p class="leafygreen-ui-1kp3ins">
The following documents,
<em>
found either in this section or other sections
of this manual
</em>
, provide information on customizing a deployment for
operation- and location-based separation:
</p>
<dl>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/workload-isolation/">
Workload Isolation in MongoDB Deployments
</a>
</dt>
<dd class="css-1ufxuu7">
MongoDB lets you specify that certain application operations use
certain
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/">
Zones
</a>
</dt>
<dd class="css-1ufxuu7">
A zone represents one or more ranges of shard key values for a
sharded collection. MongoDB routes reads and writes for sharded
data covered by a zone only to shards inside that zone. For use in
managing data distribution and deployment patterns.
</dd>
<dt>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-shard-zone/">
Manage Shard Zones
</a>
</dt>
<dd class="css-1ufxuu7">
Administrative tasks related to configuring zones in sharded
clusters
</dd>
</dl>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Further Reading
<a class="headerlink leafygreen-ui-1kepx47" href="#further-reading" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="further-reading">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/">
Write Concern
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/">
Read Preference
</a>
documents, which address capabilities related to data center
awareness.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/deploy-geographically-distributed-replica-set/">
Deploy a Geographically Redundant Self-Managed Replica Set
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$shardedDataDistribution (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-shardeddatadistribution--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-shardeddatadistribution--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output-fields" target="_self">
<span>
Output Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#return-all-sharded-data-distibution-metrics" target="_self">
<span>
Return All Sharded Data Distibution Metrics
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#return-metrics-for-a-specific-shard" target="_self">
<span>
Return Metrics for a Specific Shard
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#return-metrics-for-a-namespace" target="_self">
<span>
Return Metrics for a Namespace
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#confirm-no-orphaned-documents-remain" target="_self">
<span>
Confirm No Orphaned Documents Remain
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="pipeline">
<dt>
<code class="leafygreen-ui-1l06pbn">
$shardedDataDistribution
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-shardedDataDistribution" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-pipeline-pipe.-shardedDataDistribution">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
6.0.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Returns information on the distribution of data in sharded collections.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This aggregation stage is only available on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This aggregation stage must be run on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database. The user must
have the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-shardedDataDistribution">
<code class="leafygreen-ui-1l06pbn">
shardedDataDistribution
</code>
</a>
privilege action.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
shardedDataDistribution
</code>
stage has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate( [\n { $shardedDataDistribution: { } }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$shardedDataDistribution</span>: <!-- -->{ <!-- -->} }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Output Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#output-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="output-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
$shardedDataDistribution
</code>
stage outputs an array of documents
for each sharded collection in the database. These documents contain the
following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:30%"/>
<col style="width:15%"/>
<col style="width:55%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field Name
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Data Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ns
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Namespace of the sharded collection.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
shards
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
array
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Shards in the collection with the data distribution
information for each shard.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
shards.numOrphanedDocs
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Number of orphaned documents in the shard.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
shards.numOwnedDocuments
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Number of documents owned by the shard.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
shards.ownedSizeBytes
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Size in bytes of documents owned by the shard when
uncompressed.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
shards.orphanedSizeBytes
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Size in bytes of orphaned documents in the shard when
uncompressed.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0,
<code class="leafygreen-ui-1l06pbn">
$shardedDataDistribution
</code>
only returns
output for a collection's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary-shard">
primary shard
</a>
if the primary shard
has
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
chunks
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document">
orphaned documents
<!-- -->
.
</a>
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
After an unclean shutdown of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/">
Wired Tiger
</a>
storage engine,
<!-- -->
size and count
<!-- -->
statistics reported by
<code class="leafygreen-ui-1l06pbn">
$shardedDataDistribution
</code>
may be inaccurate.
</p>
<p class="leafygreen-ui-1kp3ins">
The amount of drift depends on the number of insert, update, or delete
operations performed between the last
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger-checkpoints">
checkpoint
</a>
and the unclean shutdown. Checkpoints
usually occur every 60 seconds. However,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances running
with non-default
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--syncdelay">
<code class="leafygreen-ui-1l06pbn">
--syncdelay
</code>
</a>
settings may have more or less frequent
checkpoints.
</p>
<p class="leafygreen-ui-1kp3ins">
Run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/validate/#mongodb-dbcommand-dbcmd.validate">
<code class="leafygreen-ui-1l06pbn">
validate
</code>
</a>
on each collection on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
to restore statistics after an unclean shutdown.
</p>
<p class="leafygreen-ui-1kp3ins">
After an unclean shutdown:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/validate/#mongodb-dbcommand-dbcmd.validate">
<code class="leafygreen-ui-1l06pbn">
validate
</code>
</a>
updates the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/collStats/#std-label-collstat-count">
count statistic
</a>
in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-dbcommand-dbcmd.collStats">
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#std-label-collStats-output">
output
</a>
with the latest value.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Other statistics like the number of documents inserted or removed in
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-dbcommand-dbcmd.collStats">
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#std-label-collStats-output">
output
</a>
are
estimates.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Return All Sharded Data Distibution Metrics
<a class="headerlink leafygreen-ui-1kepx47" href="#return-all-sharded-data-distibution-metrics" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="return-all-sharded-data-distibution-metrics">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To return all sharded data distribution metrics, run the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate([\n { $shardedDataDistribution: { } }\n])","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$shardedDataDistribution</span>: <!-- -->{ <!-- -->} }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Example output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n \"ns\": \"test.names\",\n \"shards\": [\n {\n \"shardName\": \"shard-1\",\n \"numOrphanedDocs\": 0,\n \"numOwnedDocuments\": 6,\n \"ownedSizeBytes\": 366,\n \"orphanedSizeBytes\": 0\n },\n {\n \"shardName\": \"shard-2\",\n \"numOrphanedDocs\": 0,\n \"numOwnedDocuments\": 6,\n \"ownedSizeBytes\": 366,\n \"orphanedSizeBytes\": 0\n }\n ]\n }\n]","programmingLanguage":"JSON"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ns"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"test.names"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"shards"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"shardName"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"shard-1"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"numOrphanedDocs"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"numOwnedDocuments"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">6</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ownedSizeBytes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">366</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"orphanedSizeBytes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"shardName"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"shard-2"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"numOrphanedDocs"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"numOwnedDocuments"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">6</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ownedSizeBytes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">366</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"orphanedSizeBytes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Return Metrics for a Specific Shard
<a class="headerlink leafygreen-ui-1kepx47" href="#return-metrics-for-a-specific-shard" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="return-metrics-for-a-specific-shard">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To return sharded data distribution metrics for a specific shard,
run the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate([\n { $shardedDataDistribution: { } },\n { $match: { \"shards.shardName\": \"<name>\" } }\n])","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$shardedDataDistribution</span>: <!-- -->{ <!-- -->} }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-string">"shards.shardName"</span>: <span class="lg-highlight-string">"<name of the shard>"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Return Metrics for a Namespace
<a class="headerlink leafygreen-ui-1kepx47" href="#return-metrics-for-a-namespace" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="return-metrics-for-a-namespace">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To return sharded data distribution data for a namespace, run the
following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate([\n { $shardedDataDistribution: { } },\n { $match: { \"ns\": \"<database>.<collection>\" } }\n])","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$shardedDataDistribution</span>: <!-- -->{ <!-- -->} }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-string">"ns"</span>: <span class="lg-highlight-string">"<database>.<collection>"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-shardedDataDistribution-no-orphaned-docs">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Confirm No Orphaned Documents Remain
<a class="headerlink leafygreen-ui-1kepx47" href="#confirm-no-orphaned-documents-remain" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="confirm-no-orphaned-documents-remain">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0.3, you can run an aggregation using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-shardedDataDistribution" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$shardedDataDistribution
</code>
</span>
</a>
stage to confirm no orphaned
documents remain:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.aggregate([\n { $shardedDataDistribution: { } },\n { $match: { \"ns\": \"<database>.<collection>\" } }\n])","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$shardedDataDistribution</span>: <!-- -->{ <!-- -->} }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-string">"ns"</span>: <span class="lg-highlight-string">"<database>.<collection>"</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$shardedDataDistribution
</code>
has output similar to the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n \"ns\": \"test.names\",\n \"shards\": [\n {\n \"shardName\": \"shard-1\",\n \"numOrphanedDocs\": 0,\n \"numOwnedDocuments\": 6,\n \"ownedSizeBytes\": 366,\n \"orphanedSizeBytes\": 0\n },\n {\n \"shardName\": \"shard-2\",\n \"numOrphanedDocs\": 0,\n \"numOwnedDocuments\": 6,\n \"ownedSizeBytes\": 366,\n \"orphanedSizeBytes\": 0\n }\n ]\n }\n]","programmingLanguage":"JSON"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light json leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ns"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"test.names"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"shards"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">[</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"shardName"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"shard-1"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"numOrphanedDocs"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"numOwnedDocuments"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">6</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ownedSizeBytes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">366</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"orphanedSizeBytes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"shardName"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"shard-2"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"numOrphanedDocs"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"numOwnedDocuments"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">6</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"ownedSizeBytes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">366</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"orphanedSizeBytes"</span><span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">]</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-punctuation">]</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Ensure that
<code class="leafygreen-ui-1l06pbn">
"numOrphanedDocs"
</code>
is
<code class="leafygreen-ui-1l06pbn">
0
</code>
for each shard in the
cluster.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/replica-set-rollbacks/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Rollbacks During Replica Set Failover
<a class="headerlink leafygreen-ui-1kepx47" href="#rollbacks-during-replica-set-failover" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rollbacks-during-replica-set-failover">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#collect-rollback-data" target="_self">
<span>
Collect Rollback Data
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#avoid-replica-set-rollbacks" target="_self">
<span>
Avoid Replica Set Rollbacks
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#rollback-considerations" target="_self">
<span>
Rollback Considerations
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
A rollback reverts write operations on a former
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
when the
member rejoins its
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
after a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-failover">
failover
</a>
.
A rollback is necessary only if the primary had accepted write
operations that the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondaries
</a>
had
<strong>
not
</strong>
successfully replicated before the primary stepped down. When the
primary rejoins the set as a secondary, it reverts, or "rolls back," its
write operations to maintain database consistency with the other
members.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB attempts to avoid rollbacks, which should be rare. When a
rollback does occur, it is often the result of a network
partition. Secondaries that can not keep up with the throughput of
operations on the former primary, increase the size and impact of the
rollback.
</p>
<p class="leafygreen-ui-1kp3ins">
A rollback does
<em>
not
</em>
occur if the write operations replicate to another
member of the replica set before the primary steps down
<em>
and
</em>
if that
member remains available and accessible to a majority of the replica
set.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-rollback-data-files">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Collect Rollback Data
<a class="headerlink leafygreen-ui-1kepx47" href="#collect-rollback-data" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="collect-rollback-data">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Configure Rollback Data
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-rollback-data" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configure-rollback-data">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.createRollbackDataFiles">
<code class="leafygreen-ui-1l06pbn">
createRollbackDataFiles
</code>
</a>
parameter
controls whether or not rollback files are created during rollbacks.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-rollback-data">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Rollback Data
<a class="headerlink leafygreen-ui-1kepx47" href="#rollback-data" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rollback-data">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
By default, when a rollback occurs, MongoDB writes the rollback data to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-BSON">
BSON
</a>
files.
</p>
<p class="leafygreen-ui-1kp3ins">
For each collection whose data is rolled back, the rollback files are located in
a
<code class="leafygreen-ui-1l06pbn">
<dbpath>/rollback/<collectionUUID>
</code>
directory and have filenames of the
form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"removed.<timestamp>.bson"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">removed.<timestamp>.bson</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For example, if data for the collection
<code class="leafygreen-ui-1l06pbn">
comments
</code>
in the
<code class="leafygreen-ui-1l06pbn">
reporting
</code>
database rolled back:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"<dbpath>/rollback/20f74796-d5ea-42f5-8c95-f79b39bad190/removed.2020-02-19T04-57-11.0.bson"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1agdxuk" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><dbpath>/rollback/20f74796-d5ea-42f5-8c95-f79b39bad190/removed.2020-02-19T04-57-11.0.bson</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
where
<code class="leafygreen-ui-1l06pbn">
<dbpath>
</code>
is the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath">
<code class="leafygreen-ui-1l06pbn">
dbPath
</code>
.
</a>
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Collection Name
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To get the collection name, you can search for
<code class="leafygreen-ui-1l06pbn">
rollback file
</code>
in the
MongoDB log. For example, if the log file is
<code class="leafygreen-ui-1l06pbn">
/var/log/mongodb/mongod.log
</code>
, you can use
<code class="leafygreen-ui-1l06pbn">
grep
</code>
to search for instances
of
<code class="leafygreen-ui-1l06pbn">
"rollback file"
</code>
in the log:
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"grep \"rollback file\" /var/log/mongodb/mongod.log","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">grep <span class="lg-highlight-string">"rollback file"</span> <!-- -->/var/log/mongodb/mongod.log</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Alternatively, you can loop through all the databases and run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.getCollectionInfos/#mongodb-method-db.getCollectionInfos">
<code class="leafygreen-ui-1l06pbn">
db.getCollectionInfos()
</code>
</a>
for the specific UUID until you get a match.
For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var mydatabases=db.adminCommand(\"listDatabases\").databases;\nvar foundcollection=false;\n\nfor (var i = 0; i < mydatabases.length; i++) {\n let mdb = db.getSiblingDB(mydatabases[i].name);\n collections = mdb.getCollectionInfos( { \"info.uuid\": UUID(\"20f74796-d5ea-42f5-8c95-f79b39bad190\") } );\n\n for (var j = 0; j < collections.length; j++) { // Array of 1 element\n foundcollection=true;\n print(mydatabases[i].name + '.' + collections[j].name);\n break;\n }\n\n if (foundcollection) { break; }\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> mydatabases<!-- -->=<!-- -->db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(<span class="lg-highlight-string">"listDatabases"</span>).<span class="lg-highlight-property">databases</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> foundcollection<!-- -->=<span class="lg-highlight-literal">false</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">for</span> <!-- -->(<span class="lg-highlight-keyword">var</span> i <!-- -->= <span class="lg-highlight-number">0</span>; <!-- -->i <!-- -->< <!-- -->mydatabases.<span class="lg-highlight-property">length</span>; <!-- -->i<!-- -->+<!-- -->+<!-- -->) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">let</span> mdb <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getSiblingDB</span>(<!-- -->mydatabases<!-- -->[<!-- -->i].<span class="lg-highlight-property">name</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->collections <!-- -->= <!-- -->mdb.<span class="lg-highlight-title lg-highlight-function">getCollectionInfos</span>( <!-- -->{ <span class="lg-highlight-string">"info.uuid"</span>: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"20f74796-d5ea-42f5-8c95-f79b39bad190"</span>) } )<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">for</span> <!-- -->(<span class="lg-highlight-keyword">var</span> j <!-- -->= <span class="lg-highlight-number">0</span>; <!-- -->j <!-- -->< <!-- -->collections.<span class="lg-highlight-property">length</span>; <!-- -->j<!-- -->+<!-- -->+<!-- -->) <!-- -->{ <span class="lg-highlight-comment">// Array of 1 element</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->foundcollection<!-- -->=<span class="lg-highlight-literal">true</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">print</span>(<!-- -->mydatabases<!-- -->[<!-- -->i].<span class="lg-highlight-property">name</span> <!-- -->+ <span class="lg-highlight-string">'.'</span> <!-- -->+ <!-- -->collections<!-- -->[<!-- -->j].<span class="lg-highlight-property">name</span>)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">break</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> <!-- -->(<!-- -->foundcollection) <!-- -->{ <span class="lg-highlight-keyword">break</span>; <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Rollback Data Exclusion
<a class="headerlink leafygreen-ui-1kepx47" href="#rollback-data-exclusion" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rollback-data-exclusion">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If the operation to roll back is a collection drop or a document
deletion, the rollback of the collection drop or document deletion
is not written to the rollback data directory.
</p>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If write operations use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-number-">
<code class="leafygreen-ui-1l06pbn">
{ w: 1 }
</code>
</a>
write concern,
the rollback directory may exclude writes submitted after an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog-hole">
oplog hole
</a>
if the primary restarts before the write operation
completes.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Read Rollback Data
<a class="headerlink leafygreen-ui-1kepx47" href="#read-rollback-data" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-rollback-data">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To read the contents of the rollback files, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/bsondump/#mongodb-binary-bin.bsondump" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
bsondump
</code>
</span>
</a>
.
Based on the content and the knowledge of their applications,
administrators can decide the next course of action to take.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-rollback-avoid">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Avoid Replica Set Rollbacks
<a class="headerlink leafygreen-ui-1kepx47" href="#avoid-replica-set-rollbacks" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="avoid-replica-set-rollbacks">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For replica sets, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-number-">
<code class="leafygreen-ui-1l06pbn">
{ w: 1 }
</code>
</a>
only provides acknowledgment of write
operations on the primary. Data may be rolled back if the primary steps
down before the write operations have replicated to any of the
secondaries. This includes data written in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
multi-document
transactions
</a>
that commit using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-number-">
<code class="leafygreen-ui-1l06pbn">
{ w: 1 }
</code>
</a>
write concern.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Journaling and Write Concern
<code class="leafygreen-ui-1l06pbn">
majority
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#journaling-and-write-concern-majority" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="journaling-and-write-concern-majority">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To prevent rollbacks of data that have been acknowledged to the client,
run all voting members with journaling enabled and use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-w">
{ w:
"majority" } write concern
</a>
to guarantee that the write operations
propagate to a majority of the replica set nodes before returning with
acknowledgment to the issuing client.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0,
<code class="leafygreen-ui-1l06pbn">
{ w: "majority" }
</code>
is the default write concern
for
<em>
most
</em>
MongoDB deployments. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-default-behavior">
Implicit Default Write Concern
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
With
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault">
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
,
MongoDB does not wait for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
w: "majority"
</code>
</a>
writes to be written to the on-disk journal before acknowledging the
writes. As such,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
write operations could
possibly roll back in the event of a transient loss (e.g. crash and
restart) of a majority of nodes in a given replica set.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Visibility of Data That Can Be Rolled Back
<a class="headerlink leafygreen-ui-1kepx47" href="#visibility-of-data-that-can-be-rolled-back" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="visibility-of-data-that-can-be-rolled-back">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Regardless of a write's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
, other
clients using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
read concern can see the result of a write operation before the write
operation is acknowledged to the issuing client.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Clients using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
read concern can read data which may be subsequently
<a aria-current="page" class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/">
rolled
back
</a>
during replica set failovers.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For operations in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
multi-document transaction
</a>
, when a transaction commits, all data changes
made in the transaction are saved and visible outside the transaction.
That is, a transaction will not commit some of its changes while
rolling back others.
</p>
<p class="leafygreen-ui-1kp3ins">
Until a transaction commits, the data changes made in the
transaction are not visible outside the transaction.
</p>
<p class="leafygreen-ui-1kp3ins">
However, when a transaction writes to multiple shards, not all
outside read operations need to wait for the result of the committed
transaction to be visible across the shards. For example, if a
transaction is committed and write 1 is visible on shard A but write
2 is not yet visible on shard B, an outside read at read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
can read the results of write 1 without
seeing write 2.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Rollback Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#rollback-considerations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rollback-considerations">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
User Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#user-operations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="user-operations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in version 4.2, MongoDB kills all in-progress user
operations when a member enters the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.ROLLBACK">
<code class="leafygreen-ui-1l06pbn">
ROLLBACK
</code>
</a>
state.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Builds
<a class="headerlink leafygreen-ui-1kepx47" href="#index-builds" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="index-builds">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
feature compatibility version (fcv)
</a>
<code class="leafygreen-ui-1l06pbn">
"4.2"
</code>
,
MongoDB waits for any in-progress
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations">
index builds
</a>
to finish before starting a
rollback.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For more information on the index build process, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/#std-label-index-operations">
Index Builds on Populated Collections
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Operations When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
Read Concern is Disabled
<a class="headerlink leafygreen-ui-1kepx47" href="#index-operations-when--read-concern-is-disabled" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="index-operations-when--read-concern-is-disabled">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Disabling
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
read concern prevents
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collMod/#mongodb-dbcommand-dbcmd.collMod">
<code class="leafygreen-ui-1l06pbn">
collMod
</code>
</a>
commands which modify an index from
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replica-set-rollbacks" target="_self">
<span>
rolling back
</span>
</a>
. If such an operation needs
to be rolled back, you must resync the affected nodes with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
node.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Size Limitations
<a class="headerlink leafygreen-ui-1kepx47" href="#size-limitations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="size-limitations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports the following rollback algorithms, which have different size limitations:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<strong>
Recover to a Timestamp
</strong>
, where a former primary reverts to a consistent point in time and
applies operations until it catches up to the sync source's branch of history. This is the
default rollback algorithm.
</p>
<p class="leafygreen-ui-1kp3ins">
When using this algorithm, MongoDB does not limit the amount of data you can roll back.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<strong>
Rollback via Refetch
</strong>
, where a former primary finds the common point between its
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
and the sync source's oplog. Then, the member examines and reverts all operations in its oplog until
it reaches this common point. Rollback via Refetch occurs only when the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.enableMajorityReadConcern">
<code class="leafygreen-ui-1l06pbn">
enableMajorityReadConcern
</code>
</a>
setting in your configuration file is set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
When using this algorithm, MongoDB can only roll back up to 300 MB of data.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.enableMajorityReadConcern">
<code class="leafygreen-ui-1l06pbn">
enableMajorityReadConcern
</code>
</a>
is set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
and cannot be changed.
</p>
</div>
</div>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-rollback-time-limit">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Rollback Elapsed Time Limitations
<a class="headerlink leafygreen-ui-1kepx47" href="#rollback-elapsed-time-limitations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rollback-elapsed-time-limitations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The rollback time limit defaults to 24 hours and is configurable using
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.rollbackTimeLimitSecs">
<code class="leafygreen-ui-1l06pbn">
rollbackTimeLimitSecs
</code>
</a>
parameter.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB measures elapsed time as the time between the first common
operation in the oplogs to the last entry in the oplog of the member
being rolled back.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-high-availability/">
Replica Set High Availability
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/">
Replica Set Elections
<!-- -->
.
</a>
</p>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/cursor.maxTimeMS/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
cursor.maxTimeMS()
<a class="headerlink leafygreen-ui-1kepx47" href="#cursor.maxtimems--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="cursor.maxtimems--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behaviors" target="_self">
<span>
Behaviors
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
cursor.maxTimeMS(<time limit>)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.maxTimeMS" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-cursor.maxTimeMS">
</div>
</a>
</dt>
<dd>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This page documents a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method. This is
<em>
not
</em>
the documentation for a language-specific driver, such as Node.js.
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB API drivers, refer to the language-specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
MongoDB driver documentation
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Specifies a cumulative time limit in milliseconds for processing
operations on a cursor.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</span>
</a>
method has the following prototype
form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find(\n { <query> },\n { <projection> }\n).maxTimeMS( <milliseconds> )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <<!-- -->query<!-- -->> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <<!-- -->projection<!-- -->> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">).<span class="lg-highlight-title lg-highlight-function">maxTimeMS</span>( <<!-- -->milliseconds<!-- -->> <!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</span>
</a>
method has the following
parameter:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Parameter
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
milliseconds
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Specifies a cumulative time limit in milliseconds for processing operations
on the cursor.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</span>
</a>
is not related to the
<code class="leafygreen-ui-1l06pbn">
NoCursorTimeout
</code>
query flag.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</span>
</a>
relates to processing time, while
<code class="leafygreen-ui-1l06pbn">
NoCursorTimeout
</code>
relates
to idle time. A cursor's idle time does not contribute towards its
processing time.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.maxAwaitTimeMS/#mongodb-method-cursor.maxAwaitTimeMS">
<code class="leafygreen-ui-1l06pbn">
maxAwaitTimeMS()
</code>
</a>
method sets a limit on how
long a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/tailable-cursors/#std-label-tailable-cursors-landing-page">
tailable cursor
</a>
waits
for the next response. It does not set a limit on total processing
time.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cursor-maxtimems-behaviors">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behaviors
<a class="headerlink leafygreen-ui-1kepx47" href="#behaviors" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behaviors">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB targets operations for termination if the associated cursor
exceeds its allotted time limit. MongoDB terminates operations that
exceed their allotted time limit using the same mechanism as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.killOp/#mongodb-method-db.killOp">
<code class="leafygreen-ui-1l06pbn">
db.killOp()
</code>
</a>
. MongoDB only terminates an operation at one of
its designated
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-interrupt-point">
interrupt points
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB does not count network latency between the client and the
server towards a cursor's time limit. For a sharded cluster, however,
MongoDB does include the latency between the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances towards this time limit.
</p>
<p class="leafygreen-ui-1kp3ins">
Queries that generate multiple batches of results continue to return
batches until the cursor exceeds its allotted time limit.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Session Idle Timeout Overrides
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#session-idle-timeout-overrides-maxtimems" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="session-idle-timeout-overrides-maxtimems">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB drivers and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
associate all operations with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/server-sessions/">
server session
</a>
, with the exception of unacknowledged
write operations. For operations not explicitly associated with a
session (i.e. using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo.startSession/#mongodb-method-Mongo.startSession">
<code class="leafygreen-ui-1l06pbn">
Mongo.startSession()
</code>
</a>
), MongoDB drivers
and
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
create an implicit session and associate it
with the operation.
</p>
<p class="leafygreen-ui-1kp3ins">
If a session is idle for longer than 30 minutes, the MongoDB server
marks that session as expired and may close it at any time. When the
MongoDB server closes the session, it also kills any in-progress
operations and open cursors associated with the session. This
includes cursors configured with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.noCursorTimeout/#mongodb-method-cursor.noCursorTimeout">
<code class="leafygreen-ui-1l06pbn">
noCursorTimeout()
</code>
</a>
or
a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</span>
</a>
greater than 30 minutes.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, consider a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
find()
</code>
</a>
operation with
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</span>
</a>
configured for a timeout of 31 minutes.
The server returns a cursor along with a batch of documents defined by
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.batchSize/#mongodb-method-cursor.batchSize">
<code class="leafygreen-ui-1l06pbn">
cursor.batchSize()
</code>
</a>
of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
find()
</code>
</a>
.
The session refreshes each time the application requests a new batch of
documents from the server. However, if the application takes longer than
30 minutes to process the current batch of documents, the session is
marked as expired and closed. When the server closes the session, it
also kills the cursor
<em>
despite
</em>
the cursor being configured with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</span>
</a>
greater than 30 minutes. When the
application requests the next batch of documents, the server returns an
error.
</p>
<p class="leafygreen-ui-1kp3ins">
For operations that return a cursor, if the cursor may be idle for
longer than 30 minutes, issue the operation within an explicit session
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo.startSession/#mongodb-method-Mongo.startSession">
<code class="leafygreen-ui-1l06pbn">
Mongo.startSession()
</code>
</a>
and periodically refresh the
session using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/refreshSessions/#mongodb-dbcommand-dbcmd.refreshSessions">
<code class="leafygreen-ui-1l06pbn">
refreshSessions
</code>
</a>
command. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var session = db.getMongo().startSession()\nvar sessionId = session\nsessionId // show the sessionId\n\nvar cursor = session.getDatabase(\"examples\").getCollection(\"data\").find().noCursorTimeout()\nvar refreshTimestamp = new Date() // take note of time at operation start\n\nwhile (cursor.hasNext()) {\n\n // Check if more than 5 minutes have passed since the last refresh\n if ( (new Date()-refreshTimestamp)/1000 > 300 ) {\n print(\"refreshing session\")\n db.adminCommand({\"refreshSessions\" : [sessionId]})\n refreshTimestamp = new Date()\n }\n\n // process cursor normally\n\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> session <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getMongo</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">startSession</span>(<!-- -->)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> sessionId <!-- -->= <!-- -->session</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sessionId <span class="lg-highlight-comment">// show the sessionId</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> cursor <!-- -->= <!-- -->session.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(<span class="lg-highlight-string">"examples"</span>).<span class="lg-highlight-title lg-highlight-function">getCollection</span>(<span class="lg-highlight-string">"data"</span>).<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">noCursorTimeout</span>(<!-- -->)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> refreshTimestamp <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<!-- -->) <span class="lg-highlight-comment">// take note of</span><span class="lg-highlight-comment"> time at operation </span><span class="lg-highlight-comment">start</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">while</span> <!-- -->(<!-- -->cursor.<span class="lg-highlight-title lg-highlight-function">hasNext</span>(<!-- -->)) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Check if more </span><span class="lg-highlight-comment">than 5</span><span class="lg-highlight-comment"> minutes have passed </span><span class="lg-highlight-comment">since the last refresh</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> <!-- -->( <!-- -->(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<!-- -->)<!-- -->-<!-- -->refreshTimestamp)<!-- -->/<span class="lg-highlight-number">1000</span> <!-- -->> <span class="lg-highlight-number">300</span> ) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">print</span>(<span class="lg-highlight-string">"refreshing session"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(<!-- -->{<span class="lg-highlight-string">"refreshSessions"</span> <!-- -->: <!-- -->[<!-- -->sessionId]})</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> refreshTimestamp <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<!-- -->)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-comment">// process cursor normally</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In the example operation, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
db.collection.find()
</code>
</a>
method is
associated with an explicit session. The cursor is configured with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
cursor.maxTimeMS()
</code>
</span>
</a>
to keep the cursor open for at least 31
minutes. The
<code class="leafygreen-ui-1l06pbn">
while
</code>
loop includes a block that uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/refreshSessions/#mongodb-dbcommand-dbcmd.refreshSessions">
<code class="leafygreen-ui-1l06pbn">
refreshSessions
</code>
</a>
to refresh the session every 5 minutes.
Since the session will never exceed the 30 minute idle timeout, the
cursor can remain open up to the configured
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For MongoDB drivers, defer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver documentation
</span>
</a>
for instructions and syntax for creating sessions.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-Session-Idle-Timeout">
Session Idle Timeout
</a>
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Default Timeout for All Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#default-timeout-for-all-operations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="default-timeout-for-all-operations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/cluster-parameters/defaultMaxTimeMS/#mongodb-parameter-param.defaultMaxTimeMS">
<code class="leafygreen-ui-1l06pbn">
defaultMaxTimeMS
</code>
</a>
cluster parameter to specify a default time limit for individual read
operations to complete. If a query specifies a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.maxTimeMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxTimeMS()
</code>
</span>
</a>
option, that value overrides the
<code class="leafygreen-ui-1l06pbn">
defaultMaxTimeMS
</code>
value.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<div class="leafygreen-ui-vg7qwp" role="note">
<h2 class="leafygreen-ui-2xicti">
Example
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
The following query specifies a time limit of 50 milliseconds:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find({description: /August [0-9]+, 1969/}).maxTimeMS(50)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->{<span class="lg-highlight-attr">description</span>: <span class="lg-highlight-regexp">/August </span><span class="lg-highlight-regexp">[0-9]</span><span class="lg-highlight-regexp">+, 1969/</span>}).<span class="lg-highlight-title lg-highlight-function">maxTimeMS</span>(<span class="lg-highlight-number">50</span>)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$atan2 (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-atan2--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-atan2--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-atan2" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-atan2">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns the inverse tangent (arc tangent) of
<code class="leafygreen-ui-1l06pbn">
y / x
</code>
,
where
<code class="leafygreen-ui-1l06pbn">
y
</code>
and
<code class="leafygreen-ui-1l06pbn">
x
</code>
are the first and second values passed to the
expression respectively.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $atan2: [ <expression>, <expression> ] }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$atan2</span>: <!-- -->[ <!-- --><expression 1>, <expression 2> ] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
takes any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to a number.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
returns values in radians. Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/radiansToDegrees/#mongodb-expression-exp.-radiansToDegrees">
<code class="leafygreen-ui-1l06pbn">
$radiansToDegrees
</code>
</a>
operator to convert the output value
from radians to degrees.
</p>
<p class="leafygreen-ui-1kp3ins">
By default
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
returns values as a
<code class="leafygreen-ui-1l06pbn">
double
</code>
.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
can also return values as a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self">
<span>
128-bit decimal
</span>
</a>
as long as the
<code class="leafygreen-ui-1l06pbn">
<expression>
</code>
resolves to a 128-bit decimal value.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
</dd>
</dl>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
null
</code>
and
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#null-and-nan" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="null-and-nan">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If either argument given to
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
is
<code class="leafygreen-ui-1l06pbn">
null
</code>
, the expression returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
. If either argument is
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
, the expression returns
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
.
If one argument is
<code class="leafygreen-ui-1l06pbn">
null
</code>
and the other is
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
, the expression returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:85%"/>
<col style="width:15%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Results
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $atan2: [ NaN, <value> ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $atan2: [ <value>, NaN ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $atan2: [ null, <value> ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
null
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $atan2: [ <value>, null ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
null
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $atan2: [ NaN, null ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
null
</code>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $atan2: [ null, NaN ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
null
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-8">
<div aria-label="Tabs to describe usage of degrees/radians" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_tno508epl" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_ytcazhdh0" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Inverse Tangent of Value in Degrees
</div>
</button>
<button aria-controls="_hbbksewyd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_5vzmxoshv" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Inverse Tangent of Value in Radians
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_zcbdfxctu" class="" id="_ysr6mbetz" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
trigonometry
</code>
collection contains a document that
stores three sides of a right-angle triangle:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"side_a\" : NumberDecimal(\"3\"),\n \"side_b\" : NumberDecimal(\"4\"),\n \"hypotenuse\" : NumberDecimal(\"5\")\n}","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"4"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
expression to calculate the angle adjacent
to
<code class="leafygreen-ui-1l06pbn">
side_a
</code>
and add it to the input document using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
<code class="leafygreen-ui-1l06pbn">
$addFields
</code>
</a>
pipeline stage.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trigonometry.aggregate([\n {\n $addFields : {\n \"angle_a\" : {\n $radiansToDegrees : {\n $atan2 : [ \"$side_b\", \"$side_a\" ]\n }\n }\n }\n }\n])","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.trigonometry.aggregate([</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$addFields</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$radiansToDegrees</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$atan2</span> : [ <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$side_b</span><span class="lg-highlight-string">"</span>, <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$side_a</span><span class="lg-highlight-string">"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/radiansToDegrees/#mongodb-expression-exp.-radiansToDegrees">
<code class="leafygreen-ui-1l06pbn">
$radiansToDegrees
</code>
</a>
expression converts the
radian value returned by
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
to the equivalent
value in degrees.
</p>
<p class="leafygreen-ui-1kp3ins">
The command returns the following output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"side_a\" : NumberDecimal(\"3\"),\n \"side_b\" : NumberDecimal(\"4\"),\n \"hypotenuse\" : NumberDecimal(\"5\"),\n \"angle_a\" : NumberDecimal(\"53.13010235415597870314438744090658\")\n}","programmingLanguage":"Bash"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"4"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"53.13010235415597870314438744090658"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Since
<code class="leafygreen-ui-1l06pbn">
side_b
</code>
and
<code class="leafygreen-ui-1l06pbn">
side_a
</code>
are stored as
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self">
<span>
128-bit decimals
</span>
</a>
, the output of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
is a 128-bit decimal.
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_wd5mu8pmb" class="leafygreen-ui-38lglc" id="_x9rwll6te" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
trigonometry
</code>
collection contains a document that
stores three sides of a right-angle triangle:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"side_a\" : NumberDecimal(\"3\"),\n \"side_b\" : NumberDecimal(\"4\"),\n \"hypotenuse\" : NumberDecimal(\"5\")\n}","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"4"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
expression to calculate the angle adjacent
to
<code class="leafygreen-ui-1l06pbn">
side_a
</code>
and add it to the input document using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
<code class="leafygreen-ui-1l06pbn">
$addFields
</code>
</a>
pipeline stage.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.trigonometry.aggregate([\n {\n $addFields : {\n \"angle_a\" : {\n $atan2 : [ \"$side_b\", \"$side_a\" ]\n }\n }\n }\n])","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.trigonometry.aggregate([</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$addFields</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable">$atan2</span> : [ <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$side_b</span><span class="lg-highlight-string">"</span>, <span class="lg-highlight-string">"</span><span class="lg-highlight-variable lg-highlight-string">$side_a</span><span class="lg-highlight-string">"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The command returns the following output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"5c50782193f833234ba90d85\"),\n \"side_a\" : NumberDecimal(\"3\"),\n \"side_b\" : NumberDecimal(\"4\"),\n \"hypotenuse\" : NumberDecimal(\"5\"),\n \"angle_a\" : NumberDecimal(\"0.9272952180016122324285124629224287\")\n}","programmingLanguage":"Bash"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id"</span> : ObjectId(<span class="lg-highlight-string">"5c50782193f833234ba90d85"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_a"</span> : NumberDecimal(<span class="lg-highlight-string">"3"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"side_b"</span> : NumberDecimal(<span class="lg-highlight-string">"4"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hypotenuse"</span> : NumberDecimal(<span class="lg-highlight-string">"5"</span>),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"angle_a"</span> : NumberDecimal(<span class="lg-highlight-string">"0.9272952180016122324285124629224287"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Since
<code class="leafygreen-ui-1l06pbn">
side_b
</code>
and
<code class="leafygreen-ui-1l06pbn">
side_a
</code>
are stored as
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#std-label-shell-type-decimal" target="_self">
<span>
128-bit decimals
</span>
</a>
, the output of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-atan2" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$atan2
</code>
</span>
</a>
is a 128-bit decimal.
</p>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/data-modeling/schema-design-process/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Schema Design Process
<a class="headerlink leafygreen-ui-1kepx47" href="#schema-design-process" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="schema-design-process">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#use-cases" target="_self">
<span>
Use Cases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#tasks" target="_self">
<span>
Tasks
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#identify-your-workload" target="_self">
<span>
Identify your workload
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#map-relationships" target="_self">
<span>
Map relationships
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#apply-design-patterns" target="_self">
<span>
Apply design patterns
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-indexes" target="_self">
<span>
Create indexes
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The schema design process helps you prepare an effective schema for your
application. Following the schema design process helps you identify what
data your application needs and how to best organize your data to
optimize performance.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Use Cases
<a class="headerlink leafygreen-ui-1kepx47" href="#use-cases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-cases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Planning and designing your schema is best done early in your
application development process. Starting your application with good
data modeling practices helps prevent schema and performance issues as
your application grows. When you follow schema design practices early
and appropriately, you can achieve better performance and make it easier
to scale your application in the future.
</p>
<p class="leafygreen-ui-1kp3ins">
You can design your schema iteratively and modify your schema as the
needs of your application change. MongoDB provides ways to seamlessly
modify your schema without downtime. However, it can still be difficult
to modify large-scale schemas that are used in production.
</p>
<p class="leafygreen-ui-1kp3ins">
When you design your schema, you may need to strike a balance between
performance and simplicity. Sometimes, the most performant schema takes
many iterations and a great deal of testing to achieve. Depending on
your application and the importance of optimization, you may want to
establish a simple schema to cover basic functionality, before spending
time on optimizations.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Tasks
<a class="headerlink leafygreen-ui-1kepx47" href="#tasks" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="tasks">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The schema design process consists of the following steps:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Identify the operations that your application runs most\nfrequently. See Identify Application Workload.","name":"Identify your workload"},{"@type":"HowToStep","text":"Identify the relationships in your application's data and decide\nwhether to link or embed related data. See\nMap Schema Relationships.","name":"Map relationships"},{"@type":"HowToStep","text":"Apply schema design patterns to optimize reads and writes. See\nApply Design Patterns.","name":"Apply design patterns"},{"@type":"HowToStep","text":"Create indexes to support common query patterns. See\nCreate Indexes to Support Your Queries.","name":"Create indexes"}],"name":"Tasks","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Identify your workload
<a class="headerlink leafygreen-ui-1kepx47" href="#identify-your-workload" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="identify-your-workload">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Identify the operations that your application runs most
frequently. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/schema-design-process/identify-workload/#std-label-data-modeling-identify-workload">
Identify Application Workload
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Map relationships
<a class="headerlink leafygreen-ui-1kepx47" href="#map-relationships" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="map-relationships">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Identify the relationships in your application's data and decide
whether to link or embed related data. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/schema-design-process/map-relationships/#std-label-data-modeling-map-relationships">
Map Schema Relationships
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Apply design patterns
<a class="headerlink leafygreen-ui-1kepx47" href="#apply-design-patterns" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="apply-design-patterns">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Apply schema design patterns to optimize reads and writes. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/schema-design-process/apply-patterns/#std-label-data-modeling-apply-patterns">
Apply Design Patterns
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#create-indexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create indexes to support common query patterns. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/schema-design-process/create-indexes/#std-label-create-indexes-to-support-queries">
Create Indexes to Support Your Queries
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/fsync/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
fsync
<a class="headerlink leafygreen-ui-1kepx47" href="#fsync" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="fsync">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self">
<span>
Command Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self">
<span>
Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.fsync" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.fsync">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Flushes all pending writes from the storage layer to disk. When the
<code class="leafygreen-ui-1l06pbn">
lock
</code>
field is set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, it sets a lock on the server or cluster to prevent
additional writes until the lock is released.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.1 (also available starting in 7.0.2,
6.0.11, and 5.0.22)
<!-- -->
the
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/fsyncUnlock/#mongodb-dbcommand-dbcmd.fsyncUnlock">
<code class="leafygreen-ui-1l06pbn">
fsyncUnlock
</code>
</a>
commands
<!-- -->
can run on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
to lock and unlock a sharded cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
As applications write data, MongoDB records the data in the storage layer
and then writes the data to disk.
</p>
<p class="leafygreen-ui-1kp3ins">
Run
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
when you want to flush writes to disk.
</p>
<p class="leafygreen-ui-1kp3ins">
To provide
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-durable">
durable
</a>
data,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger-checkpoints">
checkpoints
</a>
. For more
details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journaling-wiredTiger">
Journaling and the WiredTiger Storage Engine
<!-- -->
.
</a>
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Servers maintain an fsync lock count. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.fsync" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
</span>
</a>
command with
the
<code class="leafygreen-ui-1l06pbn">
lock
</code>
field set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
increments the lock count while the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/fsyncUnlock/#mongodb-dbcommand-dbcmd.fsyncUnlock">
<code class="leafygreen-ui-1l06pbn">
fsyncUnlock
</code>
</a>
command decrements it. To enable writes on a locked
server or cluster, call the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/fsyncUnlock/#mongodb-dbcommand-dbcmd.fsyncUnlock">
<code class="leafygreen-ui-1l06pbn">
fsyncUnlock
</code>
</a>
command until the lock
count reaches zero.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Use this command to block writes when you want to perform backup
operations.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
In
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
, this command can also be run through the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.fsyncLock/#mongodb-method-db.fsyncLock">
<code class="leafygreen-ui-1l06pbn">
db.fsyncLock()
</code>
</a>
helper method
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
Helper methods are convenient for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
users, but they may not
return the same level of information as database commands. In cases where
the convenience is not needed or the additional return fields are required,
use the database command.
</p>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is not supported in M0, M2, M5, and M10+ clusters.
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n fsync: 1,\n lock: <boolean>,\n fsyncLockAcquisitionTimeout: <integer>,\n comment: <any>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fsync</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lock</span>: <<span class="lg-highlight-title lg-highlight-class">Boolean</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fsyncLockAcquisitionTimeout</span>: <<!-- -->integer<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <<!-- -->any<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:60%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Enter "1" to apply
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.fsync" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
.
</span>
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fsyncLockAcquisitionTimeoutMillis
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. Specifies the amount of time in milliseconds to wait to
acquire locks. If the lock acquisition operation times out, the
command returns a failed response.
</p>
<p class="leafygreen-ui-1kp3ins">
Default:
<code class="leafygreen-ui-1l06pbn">
90000
</code>
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
7.1
</em>
.
</p>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
lock
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. Takes a lock on the server or cluster and blocks all
write operations. Each
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
with
<code class="leafygreen-ui-1l06pbn">
lock
</code>
operation
takes a lock.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
comment
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
any
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. A user-provided comment to attach to this command. Once set, this
comment appears alongside records of this command in the following
locations:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
mongod log messages
</a>
, in the
<code class="leafygreen-ui-1l06pbn">
attr.command.cursor.comment
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler">
Database profiler
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp">
<code class="leafygreen-ui-1l06pbn">
currentOp
</code>
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
A comment can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON type
</a>
(string, integer, object, array, etc).
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#considerations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="considerations">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.fsync" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
</span>
</a>
command with the
<code class="leafygreen-ui-1l06pbn">
lock
</code>
option ensures that the data files are safe to copy
using low-level backup utilities such as
<code class="leafygreen-ui-1l06pbn">
cp
</code>
,
<code class="leafygreen-ui-1l06pbn">
scp
</code>
, or
<code class="leafygreen-ui-1l06pbn">
tar
</code>
. A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
started using the copied
files contains user-written data that is indistinguishable from the
user-written data on the locked
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The data files of a locked
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
may change due to
operations such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journal-process">
journaling syncs
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger-checkpoints">
WiredTiger snapshots
</a>
. While
this has no affect on the logical data (e.g. data accessed by
clients), some backup utilities may detect these changes and emit
warnings or fail with errors. For more information on MongoDB-
recommended backup utilities and procedures, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/backups/">
Backup Methods for a Self-Managed Deployment
<!-- -->
.
</a>
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Impact on Larger Deployments
<a class="headerlink leafygreen-ui-1kepx47" href="#impact-on-larger-deployments" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="impact-on-larger-deployments">
</div>
</a>
</h3>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
7.1
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
When the
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
command runs on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
, it performs the fsync
operation on the entire cluster. By setting the
<code class="leafygreen-ui-1l06pbn">
lock
</code>
field to
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
it sets a lock on the cluster, preventing additional writes.
</p>
<p class="leafygreen-ui-1kp3ins">
To take a usable self-managed backup, before locking a sharded cluster:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Ensure that no chunk migration, resharding, or DDL operations are active.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Stop the balancer to prevent additional chunk migrations from starting.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Alternatives with Journaling
<a class="headerlink leafygreen-ui-1kepx47" href="#alternatives-with-journaling" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="alternatives-with-journaling">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-program-mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
has
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-journal">
journaling
</a>
enabled, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/backup-with-filesystem-snapshots/#std-label-backup-with-journaling">
a file system or volume/block level snapshot tool
</a>
to create a backup of the data set and the journal together as a single unit.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Lock Count
<a class="headerlink leafygreen-ui-1kepx47" href="#lock-count" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="lock-count">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
command returns a document includes a
<code class="leafygreen-ui-1l06pbn">
lockCount
</code>
field. When
run on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-program-mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
, the count indicates the number of fsync locks set on
the server.
</p>
<p class="leafygreen-ui-1kp3ins">
When run on a sharded cluster,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
sends the fsync operation to
each shard and returns the results, which includes the
<code class="leafygreen-ui-1l06pbn">
lockCount
</code>
for each.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
lockCount
</code>
field is greater than zero, all writes
are blocked on the server and cluster. To reduce the lock
count, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/fsyncUnlock/#mongodb-dbcommand-dbcmd.fsyncUnlock">
<code class="leafygreen-ui-1l06pbn">
fsyncUnlock
</code>
</a>
command.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Fsync Locks after Failures
<a class="headerlink leafygreen-ui-1kepx47" href="#fsync-locks-after-failures" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="fsync-locks-after-failures">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Fsync locks execute on the primary in a replica set or sharded cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
If the primary goes down or becomes unreachable due to network issues, the
cluster
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-elections">
elects
</a>
a new primary from the available
secondaries. If a primary with an fsync lock goes down, the new primary does
<strong>
not
</strong>
retain the fsync lock and can handle write operations. When elections
occur during backup operations, the resulting backup may be inconsistent or
unusable.
</p>
<p class="leafygreen-ui-1kp3ins">
To recover from the primary going down:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/fsyncUnlock/#mongodb-dbcommand-dbcmd.fsyncUnlock">
<code class="leafygreen-ui-1l06pbn">
fsyncUnlock
</code>
</a>
command until the lock count reaches zero
to release the lock on all nodes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Issue the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.fsync" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
</span>
</a>
command to reestablish the fsync lock on the
cluster.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Restart the backup.
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
Additionally, fsync locks are persistent. When the old primary comes online
again, you need to use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/fsyncUnlock/#mongodb-dbcommand-dbcmd.fsyncUnlock">
<code class="leafygreen-ui-1l06pbn">
fsyncUnlock
</code>
</a>
command to release the lock
on the node.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Fsync Lock
<a class="headerlink leafygreen-ui-1kepx47" href="#fsync-lock" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="fsync-lock">
</div>
</a>
</h3>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.fsync" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
</span>
</a>
command with the
<code class="leafygreen-ui-1l06pbn">
lock
</code>
option ensures that the data files are safe to copy
using low-level backup utilities such as
<code class="leafygreen-ui-1l06pbn">
cp
</code>
,
<code class="leafygreen-ui-1l06pbn">
scp
</code>
, or
<code class="leafygreen-ui-1l06pbn">
tar
</code>
. A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
started using the copied
files contains user-written data that is indistinguishable from the
user-written data on the locked
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The data files of a locked
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
may change due to
operations such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journal-process">
journaling syncs
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger-checkpoints">
WiredTiger snapshots
</a>
. While
this has no affect on the logical data (e.g. data accessed by
clients), some backup utilities may detect these changes and emit
warnings or fail with errors. For more information on MongoDB-
recommended backup utilities and procedures, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/backups/">
Backup Methods for a Self-Managed Deployment
<!-- -->
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
command can lock an individual
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-program-mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance or a
sharded cluster through
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
. When run with the
<code class="leafygreen-ui-1l06pbn">
lock
</code>
field
set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, the fsync operation flushes all data to the storage layer and
blocks all additional write operations until you unlock the instance or
cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
To lock the database, use the
<code class="leafygreen-ui-1l06pbn">
fsync
</code>
command to set the
<code class="leafygreen-ui-1l06pbn">
lock
</code>
field
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { fsync: 1, lock: true } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">fsync</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">lock</span>: <span class="lg-highlight-literal">true</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns a document that includes the status of the
operation and the
<code class="leafygreen-ui-1l06pbn">
lockCount
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"info\" : \"now locked against writes, use db.fsyncUnlock() to unlock\",\n \"lockCount\" : NumberLong(1),\n \"seeAlso\" : \"http://dochub.mongodb.org/core/fsynccommand\",\n \"ok\" : 1\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"info"</span> <!-- -->: <span class="lg-highlight-string">"now locked against writes, use db.fsyncUnlock() to unlock"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"lockCount"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">1</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"seeAlso"</span> <!-- -->: <span class="lg-highlight-string">"http://dochub.mongodb.org/core/fsynccommand"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When locked, write operations are blocked. Separate connections may continue
read operations until the first attempt at a write operation, then they also
wait until the sever or cluster is unlocked.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The fsync lock operation maintains a lock count.
</p>
<p class="leafygreen-ui-1kp3ins">
To unlock a server or cluster for writes, the lock count
must be zero. That is, for the given number of times you perform an fsync
lock, you must issue a corresponding number of unlock operations to unlock
the server or cluster for writes.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Fsync Unlock
<a class="headerlink leafygreen-ui-1kepx47" href="#fsync-unlock" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="fsync-unlock">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To unlock a server of cluster, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/fsyncUnlock/#mongodb-dbcommand-dbcmd.fsyncUnlock">
<code class="leafygreen-ui-1l06pbn">
fsyncUnlock
</code>
</a>
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { fsyncUnlock: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">fsyncUnlock</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Repeat this command as many times as needed to reduce the lock count to zero.
Once the lock count reaches zero, the server or cluster can resume writes.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Check Lock Status
<a class="headerlink leafygreen-ui-1kepx47" href="#check-lock-status" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="check-lock-status">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To check the state of the fsync lock, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.currentOp/#mongodb-method-db.currentOp">
<code class="leafygreen-ui-1l06pbn">
db.currentOp()
</code>
</a>
. Use
the following JavaScript function in the shell to test if the server or
cluster is currently locked:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"serverIsLocked = function () {\n var co = db.currentOp();\n if (co && co.fsyncLock) {\n return true;\n }\n return false;\n }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">serverIsLocked <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span> <!-- -->(<!-- -->)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> co <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">currentOp</span>(<!-- -->)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">if</span> <!-- -->(<!-- -->co <!-- -->&<!-- -->& <!-- -->co.<span class="lg-highlight-property">fsyncLock</span>) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> <span class="lg-highlight-literal">true</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> <span class="lg-highlight-literal">false</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
After loading this function into your
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
session,
call it with the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"serverIsLocked()","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-function">serverIsLocked</span>(<!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This function will return
<code class="leafygreen-ui-1l06pbn">
true
</code>
if the server or cluster is
currently locked and
<code class="leafygreen-ui-1l06pbn">
false
</code>
if the server or cluster is not locked.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/model-tree-structures-with-child-references/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Model Tree Structures with Child References
<a class="headerlink leafygreen-ui-1kepx47" href="#model-tree-structures-with-child-references" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="model-tree-structures-with-child-references">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#pattern" target="_self">
<span>
Pattern
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This page describes a data model that describes a tree-like structure
in MongoDB documents by storing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-referencing">
references
</a>
in the parent-nodes to children nodes.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#pattern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="pattern">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<em>
Child References
</em>
pattern stores each tree node in a document; in
addition to the tree node, document stores in an array the id(s) of the
node's children.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following hierarchy of categories:
</p>
<div class="figure css-5vkxs0" style="width:760px">
<img alt="Tree data model for a sample hierarchy of categories." class="leafygreen-ui-1qnf57e" height="400" src="/docs/manual/images/data-model-tree.bakedsvg.svg" style="--border-color:#C1C7C6" width="540"/>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example models the tree using
<em>
Child References
</em>
, storing
the reference to the node's children in the field
<code class="leafygreen-ui-1l06pbn">
children
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.insertMany( [\n { _id: \"MongoDB\", children: [] },\n { _id: \"dbm\", children: [] },\n { _id: \"Databases\", children: [ \"MongoDB\", \"dbm\" ] },\n { _id: \"Languages\", children: [] },\n { _id: \"Programming\", children: [ \"Databases\", \"Languages\" ] },\n { _id: \"Books\", children: [ \"Programming\" ] }\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"MongoDB"</span>, <span class="lg-highlight-attr">children</span>: <!-- -->[<!-- -->] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"dbm"</span>, <span class="lg-highlight-attr">children</span>: <!-- -->[<!-- -->] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Databases"</span>, <span class="lg-highlight-attr">children</span>: <!-- -->[ <span class="lg-highlight-string">"MongoDB"</span>, <span class="lg-highlight-string">"dbm"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Languages"</span>, <span class="lg-highlight-attr">children</span>: <!-- -->[<!-- -->] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Programming"</span>, <span class="lg-highlight-attr">children</span>: <!-- -->[ <span class="lg-highlight-string">"Databases"</span>, <span class="lg-highlight-string">"Languages"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Books"</span>, <span class="lg-highlight-attr">children</span>: <!-- -->[ <span class="lg-highlight-string">"Programming"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The query to retrieve the immediate children of a node is fast and
straightforward:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.findOne( { _id: \"Databases\" } ).children","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">findOne</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"Databases"</span> } ).<span class="lg-highlight-property">children</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can create an index on the field
<code class="leafygreen-ui-1l06pbn">
children
</code>
to enable fast
search by the child nodes:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.createIndex( { children: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">children</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can query for a node in the
<code class="leafygreen-ui-1l06pbn">
children
</code>
field to find its parent
node as well as its siblings:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.categories.find( { children: \"MongoDB\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">categories</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">children</span>: <span class="lg-highlight-string">"MongoDB"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The
<em>
Child References
</em>
pattern provides a suitable solution to tree storage
as long as no operations on subtrees are necessary. This pattern may
also provide a suitable solution for storing graphs where a node may
have multiple parents.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/Mongo.setWriteConcern/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Mongo.setWriteConcern()
<a class="headerlink leafygreen-ui-1kepx47" href="#mongo.setwriteconcern--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongo.setwriteconcern--">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
Mongo.setWriteConcern()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-Mongo.setWriteConcern" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-method-Mongo.setWriteConcern">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Sets the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-write-concern">
write concern
</a>
for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.getMongo/#mongodb-method-db.getMongo">
<code class="leafygreen-ui-1l06pbn">
Mongo()
</code>
</a>
connection object.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
Write Concern
</a>
for an introduction to write concerns
in MongoDB.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command takes the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getMongo().setWriteConcern( { w: <value>, j: <boolean>, wtimeout: <number> } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getMongo</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">setWriteConcern</span>( <!-- -->{ <span class="lg-highlight-attr">w</span>: <<!-- -->value<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-attr">j</span>: <<!-- -->boolean<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-attr">wtimeout</span>: <<!-- -->number<!-- -->> <!-- -->} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The fields are:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
w
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The number of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances that must acknowledge a write. Possible values are:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
"majority". A majority of the target instances must
acknowledge the write.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<number>. The specified number of target instances must
acknowledge the write.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<custom write concern name>. A user defined write concern, the
tagged instances must acknowledge the write.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-w">
write concern specification
</a>
for details.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
j
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A boolean value.
<code class="leafygreen-ui-1l06pbn">
j: true
</code>
requests acknowledgment that the
write operation has been written to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journaling-internals">
on-disk journal
<!-- -->
.
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
wtimeout
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The number of milliseconds to wait for acknowledgment of the
write concern.
<code class="leafygreen-ui-1l06pbn">
wtimeout
</code>
is only applicable when
<code class="leafygreen-ui-1l06pbn">
w
</code>
has a
value greater than
<code class="leafygreen-ui-1l06pbn">
1
</code>
.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In the following example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Two
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances must
acknowledge writes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
There is a
<code class="leafygreen-ui-1l06pbn">
1
</code>
second timeout to wait for write acknowledgments.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getMongo().setWriteConcern( { w: 2, wtimeout: 1000 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">getMongo</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">setWriteConcern</span>( <!-- -->{ <span class="lg-highlight-attr">w</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">wtimeout</span>: <span class="lg-highlight-number">1000</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo.getWriteConcern/#mongodb-method-Mongo.getWriteConcern">
<code class="leafygreen-ui-1l06pbn">
getWriteConcern()
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/revokeRolesFromUser/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
revokeRolesFromUser
<a class="headerlink leafygreen-ui-1kepx47" href="#revokerolesfromuser" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="revokerolesfromuser">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self">
<span>
Command Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#required-access" target="_self">
<span>
Required Access
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
revokeRolesFromUser
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.revokeRolesFromUser" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.revokeRolesFromUser">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Removes one or more roles from a user on the database where the
roles exist.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
In
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
, this command can also be run through the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.revokeRolesFromUser/#mongodb-method-db.revokeRolesFromUser">
<code class="leafygreen-ui-1l06pbn">
db.revokeRolesFromUser()
</code>
</a>
helper method
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
Helper methods are convenient for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
users, but they may not
return the same level of information as database commands. In cases where
the convenience is not needed or the additional return fields are required,
use the database command.
</p>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is not supported in M0, M2, M5, and M10+ clusters.
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n revokeRolesFromUser: \"<user>\",\n roles: [\n { role: \"<role>\", db: \"<database>\" } | \"<role>\",\n ...\n ],\n writeConcern: { <write> },\n comment: <any>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">revokeRolesFromUser</span>: <span class="lg-highlight-string">"<user>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">roles</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"<role>"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"<database>"</span> } <!-- -->| <span class="lg-highlight-string">"<role>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: <!-- -->{ <!-- --><write concern> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> comment: <any></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command takes the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
revokeRolesFromUser
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The user to remove roles from.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
roles
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
array
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The roles to remove from the user.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
writeConcern
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The level of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
for the
operation. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-specs">
Write Concern Specification
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
comment
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
any
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. A user-provided comment to attach to this command. Once set, this
comment appears alongside records of this command in the following
locations:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
mongod log messages
</a>
, in the
<code class="leafygreen-ui-1l06pbn">
attr.command.cursor.comment
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler">
Database profiler
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp">
<code class="leafygreen-ui-1l06pbn">
currentOp
</code>
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
A comment can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON type
</a>
(string, integer, object, array, etc).
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
In the
<code class="leafygreen-ui-1l06pbn">
roles
</code>
field, you can specify both
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#std-label-built-in-roles">
built-in roles
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-user-defined-roles/#std-label-user-defined-roles">
user-defined
roles
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To specify a role that exists in the same database where
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.revokeRolesFromUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
revokeRolesFromUser
</code>
</span>
</a>
runs, you can either specify the role with the name of
the role:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"readWrite\"","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"readWrite"</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Or you can specify the role with a document, as in:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ role: \"<role>\", db: \"<database>\" }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"<role>"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"<database>"</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To specify a role that exists in a different database, specify the role
with a document.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Required Access
<a class="headerlink leafygreen-ui-1kepx47" href="#required-access" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="required-access">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You must have the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-revokeRole">
<code class="leafygreen-ui-1l06pbn">
revokeRole
</code>
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#std-label-security-user-actions">
action
</a>
on a database to revoke a role on that database.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
accountUser01
</code>
user in the
<code class="leafygreen-ui-1l06pbn">
products
</code>
database has the following
roles:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"roles\" : [\n { \"role\" : \"assetsReader\",\n \"db\" : \"assets\"\n },\n { \"role\" : \"read\",\n \"db\" : \"stock\"\n },\n { \"role\" : \"readWrite\",\n \"db\" : \"products\"\n }\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"roles"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"role"</span> <!-- -->: <span class="lg-highlight-string">"assetsReader"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"db"</span> <!-- -->: <span class="lg-highlight-string">"assets"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"role"</span> <!-- -->: <span class="lg-highlight-string">"read"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"db"</span> <!-- -->: <span class="lg-highlight-string">"stock"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"role"</span> <!-- -->: <span class="lg-highlight-string">"readWrite"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"db"</span> <!-- -->: <span class="lg-highlight-string">"products"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.revokeRolesFromUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
revokeRolesFromUser
</code>
</span>
</a>
command removes the two of
the user's roles: the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-read">
<code class="leafygreen-ui-1l06pbn">
read
</code>
</a>
role on the
<code class="leafygreen-ui-1l06pbn">
stock
</code>
database and
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-readWrite">
<code class="leafygreen-ui-1l06pbn">
readWrite
</code>
</a>
role on the
<code class="leafygreen-ui-1l06pbn">
products
</code>
database, which is also
the database on which the command runs:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use products\ndb.runCommand( { revokeRolesFromUser: \"accountUser01\",\n roles: [\n { role: \"read\", db: \"stock\" },\n \"readWrite\"\n ],\n writeConcern: { w: \"majority\" }\n } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use products</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>( <!-- -->{ <span class="lg-highlight-attr">revokeRolesFromUser</span>: <span class="lg-highlight-string">"accountUser01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">roles</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"read"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"stock"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"readWrite"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">writeConcern</span>: <!-- -->{ <span class="lg-highlight-attr">w</span>: <span class="lg-highlight-string">"majority"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The user
<code class="leafygreen-ui-1l06pbn">
accountUser01
</code>
in the
<code class="leafygreen-ui-1l06pbn">
products
</code>
database now has only one
remaining role:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"roles\" : [\n { \"role\" : \"assetsReader\",\n \"db\" : \"assets\"\n }\n]","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"roles"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"role"</span> <!-- -->: <span class="lg-highlight-string">"assetsReader"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"db"</span> <!-- -->: <span class="lg-highlight-string">"assets"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/getParameter/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
getParameter
<a class="headerlink leafygreen-ui-1kepx47" href="#getparameter" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="getparameter">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self">
<span>
Command Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.getParameter" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.getParameter">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
is an administrative command for
retrieving the values of parameters. Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.adminCommand/#mongodb-method-db.adminCommand">
<code class="leafygreen-ui-1l06pbn">
db.adminCommand(
{ command } )
</code>
</a>
method to run the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
command in the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command has limited support in M0, M2, and M5 clusters.
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n getParameter: <value>,\n <parameter> : <value>,\n comment: <any>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">getParameter</span>: <<!-- -->value<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- --><<!-- -->parameter<!-- -->> <!-- -->: <<!-- -->value<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comment</span>: <<!-- -->any<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command takes the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
int, string, document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specify a value of:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
(or any integer value) to return the value for the
specified
<code class="leafygreen-ui-1l06pbn">
<parameter>
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
'*'
</code>
to return values for all parameters available to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
, ignoring the
<code class="leafygreen-ui-1l06pbn">
<parameter>
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ showDetails: true }
</code>
to return a document containing:
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-showdetails-fields">
</span>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
value
</code>
, the value that
<code class="leafygreen-ui-1l06pbn">
<parameter>
</code>
is set to
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
settableAtRuntime
</code>
, whether or not
<code class="leafygreen-ui-1l06pbn">
<parameter>
</code>
can
be set at runtime
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
settableAtStartup
</code>
, whether or not
<code class="leafygreen-ui-1l06pbn">
<parameter>
</code>
can
be set at startup
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ showDetails: true, allParameters: true }
</code>
to return a
document containing
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-showdetails-fields" target="_self">
<span>
showDetails fields
</span>
</a>
for
<strong>
all
</strong>
parameters.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ allParameters: true }
</code>
to return a document containing
<strong>
all
</strong>
parameters.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ allParameters: true, setAt: "startup" }
</code>
to return a document containing
all parameters that you can set at startup.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
8.0
</em>
.
</p>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ allParameters: true, setAt: "runtime" }
</code>
to return a document containing
all parameters that you can set at runtime.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
8.0
</em>
.
</p>
</div>
</li>
</ul>
</li>
</ul>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
<parameter>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
String name of the parameter to retrieve.
</p>
<p class="leafygreen-ui-1kp3ins">
The value for
<code class="leafygreen-ui-1l06pbn">
<value>
</code>
does not affect output.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
comment
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
any
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. A user-provided comment to attach to this command. Once set, this
comment appears alongside records of this command in the following
locations:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
mongod log messages
</a>
, in the
<code class="leafygreen-ui-1l06pbn">
attr.command.cursor.comment
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler">
Database profiler
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp">
<code class="leafygreen-ui-1l06pbn">
currentOp
</code>
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
A comment can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON type
</a>
(string, integer, object, array, etc).
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
runs on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database only, and returns
an error if run on any other database.
</p>
<p class="leafygreen-ui-1kp3ins">
The possible value for
<code class="leafygreen-ui-1l06pbn">
<parameter>
</code>
may vary depending on what version and
storage engine in use. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-getParameter-retrieve-all-params" target="_self">
<span>
Retrieve All Parameters
</span>
</a>
for an
example of listing the available parameters.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Retrieve Single Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-single-parameter" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-single-parameter">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following operation runs
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database using a value of
<code class="leafygreen-ui-1l06pbn">
saslHostName
</code>
to retrieve the value for
that parameter:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { getParameter : 1, \"saslHostName\" : 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <!-- -->getParameter <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"saslHostName"</span> <!-- -->: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The command returns the following output:
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The output may vary depending on the version and specific
configuration of your MongoDB instance.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"saslHostName\" : \"www.example.net:27018\", \"ok\" : 1 }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"saslHostName"</span> <!-- -->: <span class="lg-highlight-string">"www.example.net:27018"</span>, <span class="lg-highlight-string">"ok"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-getParameter-retrieve-all-params">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Retrieve All Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-all-parameters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-all-parameters">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following operation runs
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
with a value of
<code class="leafygreen-ui-1l06pbn">
'*'
</code>
to retrieve all parameters:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { getParameter : '*' } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <!-- -->getParameter <!-- -->: <span class="lg-highlight-string">'*'</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The output may vary depending on the version of MongoDB and the
specific configuration of the running MongoDB instance.
</p>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
for more about these parameters.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-getParameter-showdetails-single-param">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Report Details on a Single Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#report-details-on-a-single-parameter" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="report-details-on-a-single-parameter">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example runs
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
with
<code class="leafygreen-ui-1l06pbn">
{showDetails: true}
</code>
to report
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-showdetails-fields" target="_self">
<span>
details
</span>
</a>
on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.saslHostName">
<code class="leafygreen-ui-1l06pbn">
saslHostName
</code>
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { getParameter : { showDetails: true }, \"saslHostName\" : 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <!-- -->getParameter <!-- -->: <!-- -->{ <span class="lg-highlight-attr">showDetails</span>: <span class="lg-highlight-literal">true</span> }<!-- -->, <span class="lg-highlight-string">"saslHostName"</span> <!-- -->: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Example output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n saslHostName: {\n value: '<hostname>',\n settableAtRuntime: false,\n settableAtStartup: true\n },\n ok: 1\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">saslHostName</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-string">'<hostname>'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">settableAtRuntime</span>: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">settableAtStartup</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ok</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The output may vary depending on the version and specific
configuration of your MongoDB instance.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-getParameter-showdetails-all-params">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Report Details for All Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#report-details-for-all-parameters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="report-details-for-all-parameters">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example runs
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
with
<code class="leafygreen-ui-1l06pbn">
{showDetails: true, allParameters: true}
</code>
to report
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-showdetails-fields" target="_self">
<span>
details
</span>
</a>
on
<strong>
all
</strong>
parameters.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { getParameter : { showDetails: true, allParameters: true } } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <!-- -->getParameter <!-- -->: <!-- -->{ <span class="lg-highlight-attr">showDetails</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">allParameters</span>: <span class="lg-highlight-literal">true</span> } } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-getParameters-startup">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Retrieve All Startup Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-all-startup-parameters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-all-startup-parameters">
</div>
</a>
</h3>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
8.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example runs the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
command
to retrieve all startup parameters:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n getParameters: {\n allParameters: true,\n setAt: \"startup\"\n }\n} )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">getParameters</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allParameters</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setAt</span>: <span class="lg-highlight-string">"startup"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-getParameters-runtime">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Retrieve All Runtime Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-all-runtime-parameters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="retrieve-all-runtime-parameters">
</div>
</a>
</h3>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
8.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example runs the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getParameter
</code>
</span>
</a>
command
to retrieve all runtime parameters:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n getParameters: {\n allParameters: true,\n setAt: \"runtime\"\n }\n} )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">getParameters</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allParameters</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">setAt</span>: <span class="lg-highlight-string">"runtime"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/configureQueryAnalyzer/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
configureQueryAnalyzer
<a class="headerlink leafygreen-ui-1kepx47" href="#configurequeryanalyzer" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configurequeryanalyzer">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#access-control" target="_self">
<span>
Access Control
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#output" target="_self">
<span>
Output
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.configureQueryAnalyzer" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.configureQueryAnalyzer">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
7.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Configures query sampling for a collection on a replica set or
sharded cluster. Sampled queries provide information to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/analyzeShardKey/#mongodb-dbcommand-dbcmd.analyzeShardKey">
<code class="leafygreen-ui-1l06pbn">
analyzeShardKey
</code>
</a>
to calculate metrics about read and
write distribution of a shard key.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is supported in all MongoDB Atlas clusters.
For information on Atlas support for all commands, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n configureQueryAnalyzer: <string>,\n mode: <string>,\n samplesPerSecond: <double>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">configureQueryAnalyzer</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">samplesPerSecond</span>: <<!-- -->double<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
has the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:10%"/>
<col style="width:10%"/>
<col style="width:10%"/>
<col style="width:70%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Necessity
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Required
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
namespace
</a>
of the collection to configure for query
sampling.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mode
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Required
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Mode the query analyzer runs in. Must be set to either
<code class="leafygreen-ui-1l06pbn">
"full"
</code>
or
<code class="leafygreen-ui-1l06pbn">
"off"
</code>
.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
samplesPerSecond
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
double
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Number of samples per second.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
mode
</code>
is set to
<code class="leafygreen-ui-1l06pbn">
"full"
</code>
,
<code class="leafygreen-ui-1l06pbn">
samplesPerSecond
</code>
must
be set between
<code class="leafygreen-ui-1l06pbn">
0
</code>
and
<code class="leafygreen-ui-1l06pbn">
50
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
mode
</code>
is set to
<code class="leafygreen-ui-1l06pbn">
"off"
</code>
, the server ignores
<code class="leafygreen-ui-1l06pbn">
samplesPerSecond
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For details, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-samplesPerSecond-limit" target="_self">
<span>
samplesPerSecond Upper Limit
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cqa-access-control">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Access Control
<a class="headerlink leafygreen-ui-1kepx47" href="#access-control" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="access-control">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
requires one of the following roles:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-dbAdmin">
<code class="leafygreen-ui-1l06pbn">
dbAdmin
</code>
</a>
role against the database that contains the
collection being analyzed
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager">
<code class="leafygreen-ui-1l06pbn">
clusterManager
</code>
</a>
role against the cluster
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cqa-behavior">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider the following behavior when running
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Dropped Collections and Renamed Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#dropped-collections-and-renamed-collections" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="dropped-collections-and-renamed-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Query sampling is disabled automatically when the collection is dropped
or renamed. If you want to sample queries after a collection is
recreated or renamed, you must reconfigure query sampling.
</p>
</section>
<span class="leafygreen-ui-1qnjd6d" id="std-label-samplesPerSecond-limit">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
samplesPerSeconds Upper Limit
<a class="headerlink leafygreen-ui-1kepx47" href="#samplesperseconds-upper-limit" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="samplesperseconds-upper-limit">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The upper limit for
<code class="leafygreen-ui-1l06pbn">
samplesPerSecond
</code>
is
<code class="leafygreen-ui-1l06pbn">
50
</code>
. A higher rate
causes the sampled queries to fill up 10GB of disk space in less than
four days.
</p>
<p class="leafygreen-ui-1kp3ins">
This table shows the estimated disk usage for each sample rate and
duration combination:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:20%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Average Sampled Query Size (kB)
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<code class="leafygreen-ui-1l06pbn">
samplesPerSecond
</code>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Sampling Duration (Days)
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Number of Sampled Queries
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Total Size of Sampled Queries (GB)
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
0.5
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
0.1
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
60,480
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
0.03024
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
0.5
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
10
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
6,048,000
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
3.024
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
0.5
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
50
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
30,240,000
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
15.12
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
1000
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
50
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
1
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
4,320,000
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
4320
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
16,000
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
50
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
1
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
432,0000
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
69,120
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
queryAnalysisSampleExpirationSecs
<a class="headerlink leafygreen-ui-1kepx47" href="#queryanalysissampleexpirationsecs" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="queryanalysissampleexpirationsecs">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Sampled queries are stored in an internal collection that has a TTL
index with
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
. To configure
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
,
use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.queryAnalysisSampleExpirationSecs">
<code class="leafygreen-ui-1l06pbn">
queryAnalysisSampleExpirationSecs
</code>
</a>
server parameter.
Sampled queries are automatically deleted after
<code class="leafygreen-ui-1l06pbn">
queryAnalysisSampleExpirationSecs
</code>
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query Sampling Progress
<a class="headerlink leafygreen-ui-1kepx47" href="#query-sampling-progress" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="query-sampling-progress">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To monitor the query sampling process, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/currentOp/#mongodb-pipeline-pipe.-currentOp">
<code class="leafygreen-ui-1l06pbn">
$currentOp
</code>
</a>
stage. For an example, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/currentOp/#std-label-sampled-queries-currentOp-stage">
Sampled Queries
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
View Sampled Queries
<a class="headerlink leafygreen-ui-1kepx47" href="#view-sampled-queries" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="view-sampled-queries">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To see sampled queries for all collections or a specific collection, use
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listSampledQueries/#mongodb-pipeline-pipe.-listSampledQueries">
<code class="leafygreen-ui-1l06pbn">
$listSampledQueries
</code>
</a>
aggregation stage.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Limitations
<a class="headerlink leafygreen-ui-1kepx47" href="#limitations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="limitations">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot run
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
on Atlas
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/manage-clusters/#std-label-shared-tier-cluster" target="_self">
<span>
shared clusters
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/create-database-deployment/#std-label-atlas-choose-serverless" target="_self">
<span>
serverless instances
<!-- -->
.
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot run
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
on
standalone deployments.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot run
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
directly
against a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--shardsvr">
<code class="leafygreen-ui-1l06pbn">
--shardsvr
</code>
</a>
replica set.
When running on a sharded cluster,
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
must run against a
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot run
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
against
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/shardCollection/#std-label-cmd-shard-collection-timeseries">
time series
</a>
collections.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot run
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
against
collections with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe">
Queryable Encryption
<!-- -->
.
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cqa-output">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Output
<a class="headerlink leafygreen-ui-1kepx47" href="#output" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="output">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
returns a document containing fields that describe the old
configuration, if one exists, and fields describing the new
configuration.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
oldConfiguration
</code>
, if it exists, contains fields
describing the old configuration.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
newConfiguration
</code>
contains fields describing the new
configuration.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
returns a document similar to the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n ok: 1,\n oldConfiguration: {\n mode: ...,\n samplesPerSecond: ...\n }\n newConfiguration: {\n ...\n }\n}"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1jheeh3">
<pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ok: 1,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> oldConfiguration: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> mode: ...,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> samplesPerSecond: ...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> newConfiguration: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-cqa-examples">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Enable Query Sampling
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-query-sampling" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enable-query-sampling">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To enable query sampling on the
<code class="leafygreen-ui-1l06pbn">
test.students
</code>
collection at a
rate of five samples per second, use the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n configureQueryAnalyzer: \"test.students\",\n mode: \"full\",\n samplesPerSecond: 5\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">configureQueryAnalyzer</span>: <span class="lg-highlight-string">"test.students"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode</span>: <span class="lg-highlight-string">"full"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">samplesPerSecond</span>: <span class="lg-highlight-number">5</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Disable Query Sampling
<a class="headerlink leafygreen-ui-1kepx47" href="#disable-query-sampling" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="disable-query-sampling">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To disable query sampling on the
<code class="leafygreen-ui-1l06pbn">
test.students
</code>
collection,
use the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n configureQueryAnalyzer: \"test.students\",\n mode: \"off\"\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">configureQueryAnalyzer</span>: <span class="lg-highlight-string">"test.students"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode</span>: <span class="lg-highlight-string">"off"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Learn More
<a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="learn-more">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.configureQueryAnalyzer/#mongodb-method-db.collection.configureQueryAnalyzer">
<code class="leafygreen-ui-1l06pbn">
db.collection.configureQueryAnalyzer()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#std-label-currentOp-query-sampling-metrics">
currentOp Query Sampling Metrics
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listSampledQueries/#mongodb-pipeline-pipe.-listSampledQueries">
<code class="leafygreen-ui-1l06pbn">
$listSampledQueries
</code>
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/csfle/reference/libmongocrypt/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Install libmongocrypt for CSFLE
<a class="headerlink leafygreen-ui-1kepx47" href="#install-libmongocrypt-for-csfle" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="install-libmongocrypt-for-csfle">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#macos-installation" target="_self">
<span>
macOS Installation
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#windows-installation" target="_self">
<span>
Windows Installation
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#linux-installation" target="_self">
<span>
Linux Installation
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#debian" target="_self">
<span>
Debian
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#ubuntu" target="_self">
<span>
Ubuntu
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#redhat" target="_self">
<span>
RedHat
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#amazon-linux-2" target="_self">
<span>
Amazon Linux 2
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#amazon-linux-2023" target="_self">
<span>
Amazon Linux 2023
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#amazon-linux" target="_self">
<span>
Amazon Linux
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#suse" target="_self">
<span>
Suse
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Learn how to install
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
, a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/encryption-components/#std-label-csfle-reference-encryption-components">
core component
</a>
of Client-Side Field Level Encryption.
</p>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Do not build
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
from source. Use one of the installation
methods listed on this page.
</p>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
macOS Installation
<a class="headerlink leafygreen-ui-1kepx47" href="#macos-installation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="macos-installation">
</div>
</a>
</h2>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"brew install mongodb/brew/libmongocrypt","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">brew install mongodb/brew/libmongocrypt</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Windows Installation
<a class="headerlink leafygreen-ui-1kepx47" href="#windows-installation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="windows-installation">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Click
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://s3.amazonaws.com/mciuploads/libmongocrypt/windows/latest_release/libmongocrypt.tar.gz" rel="noopener noreferrer">
<span>
here
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
to begin a download with the latest release binary and
<code class="leafygreen-ui-1l06pbn">
includes
</code>
directory.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Linux Installation
<a class="headerlink leafygreen-ui-1kepx47" href="#linux-installation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="linux-installation">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Debian
<a class="headerlink leafygreen-ui-1kepx47" href="#debian" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="debian">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Import the public key used to sign the package repositories:"},{"@type":"HowToStep","text":"Add the MongoDB repository to your package sources:Change <release> in the following shell command to your platform release (e.g. \"xenial\" or \"buster\")."},{"@type":"HowToStep","text":"Update the package cache:"},{"@type":"HowToStep","text":"Install libmongocrypt:"}],"name":"Debian","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-qum8nr eccljxs0">
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
1
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Import the public key used to sign the package repositories:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo sh -c 'curl -s --location https://pgp.mongodb.com/libmongocrypt.asc | gpg --dearmor >/etc/apt/trusted.gpg.d/libmongocrypt.gpg'","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo sh -c 'curl -s --location https://pgp.mongodb.com/libmongocrypt.asc | gpg --dearmor >/etc/apt/trusted.gpg.d/libmongocrypt.gpg'</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
2
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Add the MongoDB repository to your package sources:
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Change
<code class="leafygreen-ui-1l06pbn">
<release>
</code>
in the following shell command to your platform release (e.g. "xenial" or "buster").
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo \"deb https://libmongocrypt.s3.amazonaws.com/apt/debian <release>/libmongocrypt/1.12 main\" | sudo tee /etc/apt/sources.list.d/libmongocrypt.list","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">echo "deb https://libmongocrypt.s3.amazonaws.com/apt/debian <release>/libmongocrypt/1.12 main" | sudo tee /etc/apt/sources.list.d/libmongocrypt.list</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
3
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Update the package cache:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get update","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get update</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
4
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Install
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install -y libmongocrypt-dev","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install -y libmongocrypt-dev</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Ubuntu
<a class="headerlink leafygreen-ui-1kepx47" href="#ubuntu" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ubuntu">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Import the public key used to sign the package repositories:"},{"@type":"HowToStep","text":"Add the MongoDB repository to your package sources:Change <release> in the following shell command to your platform release (e.g. \"xenial\" or \"buster\")."},{"@type":"HowToStep","text":"Update the package cache:"},{"@type":"HowToStep","text":"Install libmongocrypt:"}],"name":"Ubuntu","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-qum8nr eccljxs0">
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
1
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Import the public key used to sign the package repositories:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo sh -c 'curl -s --location https://pgp.mongodb.com/libmongocrypt.asc | gpg --dearmor >/etc/apt/trusted.gpg.d/libmongocrypt.gpg'","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo sh -c 'curl -s --location https://pgp.mongodb.com/libmongocrypt.asc | gpg --dearmor >/etc/apt/trusted.gpg.d/libmongocrypt.gpg'</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
2
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Add the MongoDB repository to your package sources:
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Change
<code class="leafygreen-ui-1l06pbn">
<release>
</code>
in the following shell command to your platform release (e.g. "xenial" or "buster").
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"echo \"deb https://libmongocrypt.s3.amazonaws.com/apt/ubuntu <release>/libmongocrypt/1.12 universe\" | sudo tee /etc/apt/sources.list.d/libmongocrypt.list","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">echo "deb https://libmongocrypt.s3.amazonaws.com/apt/ubuntu <release>/libmongocrypt/1.12 universe" | sudo tee /etc/apt/sources.list.d/libmongocrypt.list</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
3
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Update the package cache:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get update","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get update</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
4
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Install
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo apt-get install -y libmongocrypt-dev","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo apt-get install -y libmongocrypt-dev</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
RedHat
<a class="headerlink leafygreen-ui-1kepx47" href="#redhat" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="redhat">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create a repository file for the libmongocrypt package:"},{"@type":"HowToStep","text":"Install the libmongocrypt package:"}],"name":"RedHat","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-qum8nr eccljxs0">
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
1
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Create a repository file for the
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
package:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[libmongocrypt]\nname=libmongocrypt repository\nbaseurl=https://libmongocrypt.s3.amazonaws.com/yum/redhat/$releasever/libmongocrypt/1.12/x86_64\ngpgcheck=1\nenabled=1\ngpgkey=https://pgp.mongodb.com/libmongocrypt.asc","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[libmongocrypt]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">name=libmongocrypt repository</td></tr><tr class=""><td class="leafygreen-ui-7razhx">baseurl=https://libmongocrypt.s3.amazonaws.com/yum/redhat/$releasever/libmongocrypt/1.12/x86_64</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgcheck=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">enabled=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgkey=https://pgp.mongodb.com/libmongocrypt.asc</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
2
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Install the
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
package:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y libmongocrypt","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y libmongocrypt</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Amazon Linux 2
<a class="headerlink leafygreen-ui-1kepx47" href="#amazon-linux-2" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="amazon-linux-2">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create a repository file for the libmongocrypt package:"},{"@type":"HowToStep","text":"Install the libmongocrypt package:"}],"name":"Amazon Linux 2","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-qum8nr eccljxs0">
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
1
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Create a repository file for the
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
package:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[libmongocrypt]\nname=libmongocrypt repository\nbaseurl=https://libmongocrypt.s3.amazonaws.com/yum/amazon/2/libmongocrypt/1.12/x86_64\ngpgcheck=1\nenabled=1\ngpgkey=https://pgp.mongodb.com/libmongocrypt.asc","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[libmongocrypt]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">name=libmongocrypt repository</td></tr><tr class=""><td class="leafygreen-ui-7razhx">baseurl=https://libmongocrypt.s3.amazonaws.com/yum/amazon/2/libmongocrypt/1.12/x86_64</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgcheck=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">enabled=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgkey=https://pgp.mongodb.com/libmongocrypt.asc</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
2
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Install the
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
package:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y libmongocrypt","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y libmongocrypt</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Amazon Linux 2023
<a class="headerlink leafygreen-ui-1kepx47" href="#amazon-linux-2023" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="amazon-linux-2023">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create a /etc/yum.repos.d/libmongocrypt.repo\nrepository file:"},{"@type":"HowToStep","text":"Install the libmongocrypt package:"}],"name":"Amazon Linux 2023","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-qum8nr eccljxs0">
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
1
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Create a
<code class="leafygreen-ui-1l06pbn">
/etc/yum.repos.d/libmongocrypt.repo
</code>
repository file:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[libmongocrypt]\nname=libmongocrypt repository\nbaseurl=https://libmongocrypt.s3.amazonaws.com/yum/amazon/2023/libmongocrypt/1.12/x86_64\ngpgcheck=1\nenabled=1\ngpgkey=https://pgp.mongodb.com/libmongocrypt.asc"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[libmongocrypt]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">name=libmongocrypt repository</td></tr><tr class=""><td class="leafygreen-ui-7razhx">baseurl=https://libmongocrypt.s3.amazonaws.com/yum/amazon/2023/libmongocrypt/1.12/x86_64</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgcheck=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">enabled=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgkey=https://pgp.mongodb.com/libmongocrypt.asc</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
2
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Install the
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
package:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y libmongocrypt","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y libmongocrypt</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Amazon Linux
<a class="headerlink leafygreen-ui-1kepx47" href="#amazon-linux" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="amazon-linux">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create a /etc/yum.repos.d/libmongocrypt.repo\nrepository file:"},{"@type":"HowToStep","text":"Install the libmongocrypt package:"}],"name":"Amazon Linux","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-qum8nr eccljxs0">
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
1
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Create a
<code class="leafygreen-ui-1l06pbn">
/etc/yum.repos.d/libmongocrypt.repo
</code>
repository file:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[libmongocrypt]\nname=libmongocrypt repository\nbaseurl=https://libmongocrypt.s3.amazonaws.com/yum/amazon/2013.03/libmongocrypt/1.12/x86_64\ngpgcheck=1\nenabled=1\ngpgkey=https://pgp.mongodb.com/libmongocrypt.asc"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[libmongocrypt]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">name=libmongocrypt repository</td></tr><tr class=""><td class="leafygreen-ui-7razhx">baseurl=https://libmongocrypt.s3.amazonaws.com/yum/amazon/2013.03/libmongocrypt/1.12/x86_64</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgcheck=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">enabled=1</td></tr><tr class=""><td class="leafygreen-ui-7razhx">gpgkey=https://pgp.mongodb.com/libmongocrypt.asc</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
2
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Install the
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
package:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y libmongocrypt","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo yum install -y libmongocrypt</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Suse
<a class="headerlink leafygreen-ui-1kepx47" href="#suse" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="suse">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Import the public key used to sign the package repositories:"},{"@type":"HowToStep","text":"Add the repository to your package sources:Change <release> in the following shell command to your platform release (e.g. \"12\" or \"15\")."},{"@type":"HowToStep","text":"Install the libmongocrypt package:"}],"name":"Suse","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-qum8nr eccljxs0">
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
1
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Import the public key used to sign the package repositories:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo rpm --import https://pgp.mongodb.com/libmongocrypt.asc","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo rpm --import https://pgp.mongodb.com/libmongocrypt.asc</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
2
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Add the repository to your package sources:
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Change
<code class="leafygreen-ui-1l06pbn">
<release>
</code>
in the following shell command to your platform release (e.g. "12" or "15").
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo zypper addrepo --gpgcheck \"https://libmongocrypt.s3.amazonaws.com/zypper/suse/<release>/libmongocrypt/1.12/x86_64\" libmongocrypt","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo zypper addrepo --gpgcheck "https://libmongocrypt.s3.amazonaws.com/zypper/suse/<release>/libmongocrypt/1.12/x86_64" libmongocrypt</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-vq8pj5 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-18jxsvu e1ckbxcu2">
3
</div>
</div>
<div class="css-clrhqf">
<section>
<p class="leafygreen-ui-1kp3ins">
Install the
<code class="leafygreen-ui-1l06pbn">
libmongocrypt
</code>
package:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo zypper -n install libmongocrypt","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo zypper -n install libmongocrypt</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$toBool (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-tobool--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-tobool--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$toBool
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-toBool" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-toBool">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Converts a value to a boolean.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toBool" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toBool
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n $toBool: <expression>\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$toBool</span>: <<!-- -->expression<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toBool" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toBool
</code>
</span>
</a>
takes any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toBool" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toBool
</code>
</span>
</a>
is a shorthand for the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/convert/#mongodb-expression-exp.-convert">
<code class="leafygreen-ui-1l06pbn">
$convert
</code>
</a>
expression:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $convert: { input: <expression>, to: \"bool\" } }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$convert</span>: <!-- -->{ <span class="lg-highlight-attr">input</span>: <<!-- -->expression<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-attr">to</span>: <span class="lg-highlight-string">"bool"</span> } }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/convert/#mongodb-expression-exp.-convert">
<code class="leafygreen-ui-1l06pbn">
$convert
</code>
</a>
</p>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following table lists the input types that can be converted to a
boolean:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:55%"/>
<col style="width:50%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Input Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Behavior
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Array
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Binary data
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
No-op. Returns the boolean value.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Code
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Date
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Decimal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
Returns true if not zero
</div>
<div class="line">
Return false if zero
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Double
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
Returns true if not zero
</div>
<div class="line">
Return false if zero
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
Returns true if not zero
</div>
<div class="line">
Return false if zero
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
JavaScript
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Long
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
Returns true if not zero
</div>
<div class="line">
Return false if zero
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
MaxKey
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
MinKey
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Null
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Returns null
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Object
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
ObjectId
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Regular expression
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
String
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Timestamp
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns true
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
To learn more about data types in MongoDB, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON Types
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The following table lists some conversion to boolean examples:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:80%"/>
<col style="width:20%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Results
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: false}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
false
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: 1.99999}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: NumberDecimal("5")}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: NumberDecimal("0")}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
false
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: 100}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: ISODate("2018-03-26T04:38:28.044Z")}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: "false"}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: ""}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
true
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toBool: null}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
null
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Create a collection
<code class="leafygreen-ui-1l06pbn">
orders
</code>
with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.insertMany( [\n { _id: 1, item: \"apple\", qty: 5, shipped: true },\n { _id: 2, item: \"pie\", qty: 10, shipped: 0 },\n { _id: 3, item: \"ice cream\", shipped: 1 },\n { _id: 4, item: \"almonds\", qty: 2, shipped: \"true\" },\n { _id: 5, item: \"pecans\", shipped: \"false\" }, // Note: All strings convert to true\n { _id: 6, item: \"nougat\", shipped: \"\" } // Note: All strings convert to true\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">orders</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"apple"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">shipped</span>: <span class="lg-highlight-literal">true</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"pie"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">shipped</span>: <span class="lg-highlight-number">0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"ice cream"</span>, <span class="lg-highlight-attr">shipped</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"almonds"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">shipped</span>: <span class="lg-highlight-string">"true"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"pecans"</span>, <span class="lg-highlight-attr">shipped</span>: <span class="lg-highlight-string">"false"</span> }<!-- -->, <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Note: All strings </span><span class="lg-highlight-comment">convert to true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"nougat"</span>, <span class="lg-highlight-attr">shipped</span>: <span class="lg-highlight-string">""</span> } <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Note: All strings </span><span class="lg-highlight-comment">convert to true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following aggregation operation on the
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection
converts the
<code class="leafygreen-ui-1l06pbn">
shipped
</code>
to a boolean value before finding the
unshipped orders:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// Define stage to add convertedShippedFlag field with the converted shipped value\n// Because all strings convert to true, include specific handling for \"false\" and \"\"\n\nshippedConversionStage = {\n $addFields: {\n convertedShippedFlag: {\n $switch: {\n branches: [\n { case: { $eq: [ \"$shipped\", \"false\" ] }, then: false } ,\n { case: { $eq: [ \"$shipped\", \"\" ] }, then: false }\n ],\n default: { $toBool: \"$shipped\" }\n }\n }\n }\n};\n\n// Define stage to filter documents and pass only the unshipped orders\n\nunshippedMatchStage = {\n $match: { \"convertedShippedFlag\": false }\n};\n\ndb.orders.aggregate( [\n shippedConversionStage,\n unshippedMatchStage\n] )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Define stage to </span><span class="lg-highlight-comment">add convertedShippedFlag</span><span class="lg-highlight-comment"> field with the </span><span class="lg-highlight-comment">converted shipped value</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Because all strings </span><span class="lg-highlight-comment">convert to true,</span><span class="lg-highlight-comment"> include specific handling </span><span class="lg-highlight-comment">for "false" and ""</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">shippedConversionStage <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$addFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">convertedShippedFlag</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$switch</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">branches</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <span class="lg-highlight-string">"$shipped"</span>, <span class="lg-highlight-string">"false"</span> ] }<!-- -->, <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-literal">false</span> } <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <span class="lg-highlight-string">"$shipped"</span>, <span class="lg-highlight-string">""</span> ] }<!-- -->, <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">default</span>: <!-- -->{ <span class="lg-highlight-attr">$toBool</span>: <span class="lg-highlight-string">"$shipped"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Define stage to </span><span class="lg-highlight-comment">filter</span><span class="lg-highlight-comment"> documents and pass </span><span class="lg-highlight-comment">only the unshipped orders</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">unshippedMatchStage <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-string">"convertedShippedFlag"</span>: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">orders</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->shippedConversionStage<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->unshippedMatchStage</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 2, \"item\" : \"pie\", \"qty\" : 10, \"shipped\" : 0, \"convertedShippedFlag\" : false }\n{ \"_id\" : 5, \"item\" : \"pecans\", \"shipped\" : \"false\", \"convertedShippedFlag\" : false }\n{ \"_id\" : 6, \"item\" : \"nougat\", \"shipped\" : \"\", \"convertedShippedFlag\" : false }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"pie"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"shipped"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"convertedShippedFlag"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"pecans"</span>, <span class="lg-highlight-string">"shipped"</span> <!-- -->: <span class="lg-highlight-string">"false"</span>, <span class="lg-highlight-string">"convertedShippedFlag"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"nougat"</span>, <span class="lg-highlight-string">"shipped"</span> <!-- -->: <span class="lg-highlight-string">""</span>, <span class="lg-highlight-string">"convertedShippedFlag"</span> <!-- -->: <span class="lg-highlight-literal">false</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If the conversion operation encounters an error, the aggregation
operation stops and throws an error. To override this behavior, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/convert/#mongodb-expression-exp.-convert">
<code class="leafygreen-ui-1l06pbn">
$convert
</code>
</a>
instead.
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/release-notes/6.0-upgrade-standalone/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Upgrade a Standalone to 6.0
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-a-standalone-to-6.0" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-a-standalone-to-6.0">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#upgrade-recommendations-and-checklists" target="_self">
<span>
Upgrade Recommendations and Checklists
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#prerequisites" target="_self">
<span>
Prerequisites
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#download-newversion-binaries" target="_self">
<span>
Download
<!-- -->
6.0
<!-- -->
Binaries
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#upgrade-procedure" target="_self">
<span>
Upgrade Procedure
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-upgrade-procedures" target="_self">
<span>
Additional Upgrade Procedures
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Use this tutorial to upgrade from MongoDB
<!-- -->
5.0
<!-- -->
to MongoDB
<!-- -->
6.0
<!-- -->
. To upgrade to a new patch release within the same release
series, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/upgrade-revision/#std-label-upgrade-to-latest-revision">
Upgrade to the Latest Self-Managed Patch Release of MongoDB
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Familiarize yourself with the content of this document, including
thoroughly reviewing the prerequisites, prior to upgrading to MongoDB
<!-- -->
6.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
The following steps outline the procedure to upgrade a standalone
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
from version
<!-- -->
5.0
<!-- -->
to
<!-- -->
6.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
If you need guidance on upgrading to
<!-- -->
6.0
<!-- -->
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/products/consulting?tck=docs_server" target="_self">
<span>
MongoDB
professional services
</span>
</a>
offer major version upgrade support to help ensure a smooth transition
without interruption to your MongoDB application.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Upgrade Recommendations and Checklists
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-recommendations-and-checklists" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-recommendations-and-checklists">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When upgrading, consider the following:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Upgrade Version Path
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-version-path" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-version-path">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To upgrade an existing MongoDB deployment to
<!-- -->
6.0
<!-- -->
, you must be
running a
<!-- -->
5.0-series
<!-- -->
release.
</p>
<p class="leafygreen-ui-1kp3ins">
To upgrade from a version earlier than the
<!-- -->
5.0-series
<!-- -->
, you must
successively upgrade major releases until you have upgraded to
<!-- -->
5.0-series
<!-- -->
. For example, if you are running a
<!-- -->
4.4-series
<!-- -->
, you must
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0/#std-label-5.0-upgrade">
upgrade first to 5.0
</a>
<em>
before
</em>
you can upgrade to
<!-- -->
6.0
<!-- -->
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Check Driver Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#check-driver-compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="check-driver-compatibility">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Before you upgrade MongoDB, check that you're using a MongoDB
<!-- -->
6.0
<!-- -->
-compatible driver. Consult the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver documentation
</span>
</a>
for your specific driver to verify
compatibility with MongoDB
<!-- -->
6.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
Upgraded deployments that run on incompatible drivers might encounter
unexpected or undefined behavior.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Preparedness
<a class="headerlink leafygreen-ui-1kepx47" href="#preparedness" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="preparedness">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Before beginning your upgrade, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0-compatibility/">
Compatibility Changes in MongoDB 6.0
</a>
document to
ensure that your applications and deployments are compatible with
MongoDB
<!-- -->
6.0
<!-- -->
. Resolve the incompatibilities in your deployment
before starting the upgrade.
</p>
<p class="leafygreen-ui-1kp3ins">
Before upgrading MongoDB, always test your application in a staging
environment before deploying the upgrade to your production
environment.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Downgrade Consideration
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-consideration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="downgrade-consideration">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You cannot downgrade your deployment's binary version without assistance from
support.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/8.0-downgrade/#std-label-8.0-downgrade">
Downgrade
<!-- -->
8.0
<!-- -->
to
<!-- -->
7.0
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Prerequisites
<a class="headerlink leafygreen-ui-1kepx47" href="#prerequisites" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="prerequisites">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Feature Compatibility Version
<a class="headerlink leafygreen-ui-1kepx47" href="#feature-compatibility-version" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="feature-compatibility-version">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
5.0
<!-- -->
instance must have
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
set
to
<code class="leafygreen-ui-1l06pbn">
"5.0"
</code>
. To check
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">getParameter</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">featureCompatibilityVersion</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation should return a result that includes
<code class="leafygreen-ui-1l06pbn">
"featureCompatibilityVersion" : { "version" : "5.0" }
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
To set or update
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
, run the following
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { setFeatureCompatibilityVersion: \"5.0\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">setFeatureCompatibilityVersion</span>: <span class="lg-highlight-string">"5.0"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Consider Converting to Replica Set
<a class="headerlink leafygreen-ui-1kepx47" href="#consider-converting-to-replica-set" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="consider-converting-to-replica-set">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Prior to upgrading, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/convert-standalone-to-replica-set/">
converting your standalone deployment to a replica set
</a>
. Replica sets are the
recommended deployment configuration for MongoDB.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Download
<!-- -->
6.0
<!-- -->
Binaries
<a class="headerlink leafygreen-ui-1kepx47" href="#download-newversion-binaries" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-newversion-binaries">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Via Package Manager
<a class="headerlink leafygreen-ui-1kepx47" href="#via-package-manager" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="via-package-manager">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you installed MongoDB from the MongoDB
<code class="leafygreen-ui-1l06pbn">
apt
</code>
,
<code class="leafygreen-ui-1l06pbn">
yum
</code>
,
<code class="leafygreen-ui-1l06pbn">
dnf
</code>
, or
<code class="leafygreen-ui-1l06pbn">
zypper
</code>
repositories, you should upgrade to
<!-- -->
6.0
<!-- -->
using your package
manager.
</p>
<p class="leafygreen-ui-1kp3ins">
Follow the appropriate
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
6.0 installation instructions
</a>
for your Linux system. This
will involve adding a repository for the new release, then performing
the actual upgrade process.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Manually
<a class="headerlink leafygreen-ui-1kepx47" href="#manually" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="manually">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you have not installed MongoDB using a package manager, you can
manually download the MongoDB binaries from the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/try/download?tck=docs_server" target="_self">
<span>
MongoDB Download
Center
</span>
</a>
.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
6.0 installation instructions
</a>
for more information.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Upgrade Procedure
<a class="headerlink leafygreen-ui-1kepx47" href="#upgrade-procedure" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="upgrade-procedure">
</div>
</a>
</h2>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"To shut down the mongod process, use\nmongosh to connect to the instance and run the\nfollowing command:","name":"Shut down the mongod instance."},{"@type":"HowToStep","text":"Ensure that the 6.0-series binaries are in your System PATH. To\nconfirm your binary version, run the following command:The command output should indicate a 6.0-series release.","name":"Replace the 5.0 binaries with the 6.0 binaries."},{"@type":"HowToStep","text":"At this point, you can run the 6.0 binaries without the\n6.0 features that are incompatible with 5.0.To enable these 6.0 features, set the feature compatibility\nversion (fCV) to 6.0.Enabling these backwards-incompatible features can complicate the\ndowngrade process since you must remove any persisted backwards-incompatible\nfeatures before you downgrade.It is recommended that after upgrading, you allow your deployment to run\nwithout enabling these features for a burn-in period to ensure the\nlikelihood of downgrade is minimal. When you are confident that the\nlikelihood of downgrade is minimal, enable these features.Run the setFeatureCompatibilityVersion command\nagainst the admin database:This command must perform writes to an internal system\ncollection. If for any reason the command does not complete\nsuccessfully, you can safely retry the command as the operation\nis idempotent.","name":"Enable backwards-incompatible 6.0 features."}],"name":"Upgrade Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Shut down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance.
<a class="headerlink leafygreen-ui-1kepx47" href="#shut-down-the--instance." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shut-down-the--instance.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To shut down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to connect to the instance and run the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { shutdown: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">shutdown</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replace the
<!-- -->
5.0
<!-- -->
binaries with the
<!-- -->
6.0
<!-- -->
binaries.
<a class="headerlink leafygreen-ui-1kepx47" href="#replace-the--binaries-with-the--binaries." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replace-the--binaries-with-the--binaries.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Ensure that the
<!-- -->
6.0-series
<!-- -->
binaries are in your System PATH. To
confirm your binary version, run the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --version","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --version</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The command output should indicate a
<!-- -->
6.0-series
<!-- -->
release.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Enable backwards-incompatible
<!-- -->
6.0
<!-- -->
features.
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-backwards-incompatible--features." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enable-backwards-incompatible--features.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
At this point, you can run the
<!-- -->
6.0
<!-- -->
binaries without the
<!-- -->
6.0
<!-- -->
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0-compatibility/#std-label-6.0-downgrade-considerations">
features
</a>
that are incompatible with
<!-- -->
5.0
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
To enable these
<!-- -->
6.0
<!-- -->
features, set the feature compatibility
version (
<code class="leafygreen-ui-1l06pbn">
fCV
</code>
) to
<!-- -->
6.0
<!-- -->
.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Enabling these backwards-incompatible features can complicate the
downgrade process since you must remove any persisted backwards-incompatible
features before you downgrade.
</p>
<p class="leafygreen-ui-1kp3ins">
It is recommended that after upgrading, you allow your deployment to run
without enabling these features for a burn-in period to ensure the
likelihood of downgrade is minimal. When you are confident that the
likelihood of downgrade is minimal, enable these features.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
command
against the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { setFeatureCompatibilityVersion: \"6.0\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">setFeatureCompatibilityVersion</span>: <span class="lg-highlight-string">"6.0"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This command must perform writes to an internal system
collection. If for any reason the command does not complete
successfully, you can safely retry the command as the operation
is idempotent.
</p>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Upgrade Procedures
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-upgrade-procedures" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="additional-upgrade-procedures">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To upgrade a replica set, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0-upgrade-replica-set/#std-label-6.0-upgrade-replica-set">
Upgrade a Replica Set to 6.0
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To upgrade a sharded cluster, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0-upgrade-sharded-cluster/#std-label-6.0-upgrade-sharded-cluster">
Upgrade a Sharded Cluster to 6.0
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/reshardCollection/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
reshardCollection
<a class="headerlink leafygreen-ui-1kepx47" href="#reshardcollection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="reshardcollection">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self">
<span>
Command Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self">
<span>
Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#resharding-process" target="_self">
<span>
Resharding Process
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.reshardCollection" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.reshardCollection">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.reshardCollection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
</span>
</a>
command changes the shard key for
a collection and changes the distribution of your data.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
In
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
, this command can also be run through the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.reshardCollection/#mongodb-method-sh.reshardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.reshardCollection()
</code>
</a>
helper method
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
Helper methods are convenient for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
users, but they may not
return the same level of information as database commands. In cases where
the convenience is not needed or the additional return fields are required,
use the database command.
</p>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is supported in all MongoDB Atlas clusters.
For information on Atlas support for all commands, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n reshardCollection: \"<database>.<collection>\",\n key: <shardkey>,\n unique: <boolean>,\n numInitialChunks: <integer>,\n collation: { locale: \"simple\" },\n zones: [\n {\n min: <document>,\n max: <document>,\n zone: <string> | null\n },\n ...\n ],\n forceRedistribution: <bool>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">reshardCollection</span>: <span class="lg-highlight-string">"<database>.<collection>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <<!-- -->shardkey<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unique</span>: <<!-- -->boolean<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">numInitialChunks</span>: <<!-- -->integer<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">collation</span>: <!-- -->{ <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">"simple"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zones</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <!-- --><document with same shape as shardkey>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> max: <document with same shape as shardkey>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> zone: <string> | null</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ],</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> forceRedistribution: <bool></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command takes the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:25%"/>
<col style="width:20%"/>
<col style="width:75%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
namespace
</a>
of the collection to be resharded. Takes
the form
<code class="leafygreen-ui-1l06pbn">
<database>.<collection>
</code>
.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
key
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The document that specifies the new field or fields to use as the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key">
shard key
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ <field1>: <1|"hashed">, ... }
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
Set the field values to either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged">
range-based sharding
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
"hashed"
</code>
to specify a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/shardCollection/#std-label-hashed-shard-keys">
hashed shard key
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
See also
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key-indexes">
Shard Key Indexes
</a>
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
unique
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. Specify whether there is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/">
uniqueness
</a>
constraint on the shard key. Only
<code class="leafygreen-ui-1l06pbn">
false
</code>
is supported. Defaults to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
numInitialChunks
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. Specifies the initial number of chunks to create
across all shards in the cluster when resharding a collection.
The default is the number of chunks that exist for the
collection under the current shard key pattern. MongoDB will
then create and balance chunks across the cluster. The
<code class="leafygreen-ui-1l06pbn">
numInitialChunks
</code>
must result in less than
<code class="leafygreen-ui-1l06pbn">
8192
</code>
per shard.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
collation
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. If the collection specified in
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
has a default
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
</a>
, you
<em>
must
</em>
include a
collation document with
<code class="leafygreen-ui-1l06pbn">
{ locale : "simple" }
</code>
, or the
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
command fails.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
zones
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
array
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. To maintain or add
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zones
</a>
,
specify the zones for your collection in an array.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
forceRedistribution
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. If set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, the operation runs even if the new
shard key is the same as the old shard key. Use with the
<code class="leafygreen-ui-1l06pbn">
zones
</code>
option to move data to specific zones.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
7.2
</em>
.
</p>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#considerations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="considerations">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Index builds that occur during resharding might silently
fail.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Do not create indexes during the resharding process.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Do not start the resharding process if there are ongoing index builds.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Resharding Process
<a class="headerlink leafygreen-ui-1kepx47" href="#resharding-process" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="resharding-process">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In a collection resharding operation, a shard can be a:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<strong>
donor
</strong>
, which currently stores
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
chunks
</a>
for the
sharded collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<strong>
recipient
</strong>
, which stores new chunks for the sharded collection
based on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard keys
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zones
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
A shard can be donor and a recipient at the same time. The set of donor
shards is identical to the recipient shards, unless you use zones.
</p>
<p class="leafygreen-ui-1kp3ins">
The config server primary is always the resharding coordinator and
starts each phase of the resharding operation.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Initialization Phase
<a class="headerlink leafygreen-ui-1kepx47" href="#initialization-phase" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="initialization-phase">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
During the initialization phase, the resharding coordinator determines
the new data distribution for the sharded collection.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Phase
<a class="headerlink leafygreen-ui-1kepx47" href="#index-phase" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="index-phase">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
During the index phase:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Each shard recipient creates a new, empty sharded collection with the
same collection options as the existing sharded collection. This new
sharded collection is the target for where recipient shards write the
new data.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Each shard recipient builds the necessary new indexes. These include
all existing indexes on the sharded collection and an index compatible
with the new shard key pattern if such an index doesn't already exist on
the sharded collection.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Clone, Apply, and Catch-up Phase
<a class="headerlink leafygreen-ui-1kepx47" href="#clone--apply--and-catch-up-phase" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="clone--apply--and-catch-up-phase">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
During the clone, apply, and catch-up phase:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Each shard recipient clones an initial copy of the documents it would
own under the new shard key.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Each shard recipient begins applying oplog entries from operations
that happened after the recipient cloned the data.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When the estimate for the time remaining to complete the resharding
operation is under
<strong>
two seconds
</strong>
, the resharding coordinator blocks
writes for the collection.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If desired, you can manually force the resharding operation to
complete by issuing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/commitReshardCollection/#mongodb-dbcommand-dbcmd.commitReshardCollection">
<code class="leafygreen-ui-1l06pbn">
commitReshardCollection
</code>
</a>
command. This is useful if the current time estimate to complete
the resharding operation is an acceptable duration for your
collection to block writes. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/commitReshardCollection/#mongodb-dbcommand-dbcmd.commitReshardCollection">
<code class="leafygreen-ui-1l06pbn">
commitReshardCollection
</code>
</a>
command blocks writes early
and forces the resharding operation to complete. During the time
period where writes are blocked your application experiences an
increase in latency.
</p>
</div>
</div>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-resharding-commit-phase-command">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Commit Phase
<a class="headerlink leafygreen-ui-1kepx47" href="#commit-phase" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="commit-phase">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Once the resharding process reaches the commit phase, it may no longer
be aborted with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/abortReshardCollection/#mongodb-dbcommand-dbcmd.abortReshardCollection">
<code class="leafygreen-ui-1l06pbn">
abortReshardCollection
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When all shards have reached strict consistency, the resharding
coordinator commits the resharding operation and installs the new
routing table.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The resharding coordinator instructs each donor and recipient shard
primary, independently, to rename the temporary sharded collection.
The temporary collection becomes the new resharded collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Each donor shard drops the old sharded collection.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
Reshard a Collection
</a>
</p>
</div>
</div>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Reshard a Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#reshard-a-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="reshard-a-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example reshards the
<code class="leafygreen-ui-1l06pbn">
sales.orders
</code>
collection with the
new shard key
<code class="leafygreen-ui-1l06pbn">
{ order_id: 1 }
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand({\n reshardCollection: \"sales.orders\",\n key: { order_id: 1 }\n})","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">reshardCollection</span>: <span class="lg-highlight-string">"sales.orders"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-attr">order_id</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n ok: 1,\n '$clusterTime': {\n clusterTime: Timestamp(1, 1624887954),\n signature: {\n hash: Binary(Buffer.from(\"0000000000000000000000000000000000000000\", \"hex\"), 0),\n keyId: 0\n }\n },\n operationTime: Timestamp(1, 1624887947)\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ok</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">'$clusterTime'</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterTime</span>: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1624887954</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">signature</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">hash</span>: <span class="lg-highlight-title lg-highlight-class">Binary</span>(<span class="lg-highlight-title lg-highlight-class">Buffer</span>.<span class="lg-highlight-title lg-highlight-function">from</span>(<span class="lg-highlight-string">"0000000000000000000000000000000000000000"</span>, <span class="lg-highlight-string">"hex"</span>)<!-- -->, <span class="lg-highlight-number">0</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyId</span>: <span class="lg-highlight-number">0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">operationTime</span>: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1624887947</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
Reshard a Collection
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-reshardCollection-redistribute-data">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Redistribute Data to New Shards
<a class="headerlink leafygreen-ui-1kepx47" href="#redistribute-data-to-new-shards" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="redistribute-data-to-new-shards">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.2, you can reshard a collection on the same key,
which can be used to redistribute data onto new shards.
</p>
<p class="leafygreen-ui-1kp3ins">
After adding a shard to the cluster, you use the
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
command
with the
<code class="leafygreen-ui-1l06pbn">
forceRedistribution
</code>
option to redistribute data across the
cluster:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand({\n reshardCollection: \"accounts.invoices\",\n key: { store_id: \"hashed\" },\n forceRedistribution: true\n})","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">reshardCollection</span>: <span class="lg-highlight-string">"accounts.invoices"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-attr">store_id</span>: <span class="lg-highlight-string">"hashed"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">forceRedistribution</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">})</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Redistribute Data to Different Zones
<a class="headerlink leafygreen-ui-1kepx47" href="#redistribute-data-to-different-zones" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="redistribute-data-to-different-zones">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.2, you can use the
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
command to
move data into new zones without changing the shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
The following command redistributes data for the
<code class="leafygreen-ui-1l06pbn">
accounts.sales
</code>
collection
using the same shard key, moving data from zones
<code class="leafygreen-ui-1l06pbn">
zone01
</code>
and
<code class="leafygreen-ui-1l06pbn">
zone02
</code>
to
<code class="leafygreen-ui-1l06pbn">
zone03
</code>
and
<code class="leafygreen-ui-1l06pbn">
zone04
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand({\n reshardCollection: \"accounts.sales\",\n key: { region_id: \"hashed\" },\n forceRedistribution: true,\n zones: [\n {\n zone: \"zone04\",\n min: { region_id: MinKey() },\n max: { region_id: 10 }\n },\n {\n zone: \"zone05\",\n min: { region_id: 10 },\n max: { region_id: MaxKey() }\n }\n ]\n})","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">reshardCollection</span>: <span class="lg-highlight-string">"accounts.sales"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-attr">region_id</span>: <span class="lg-highlight-string">"hashed"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">forceRedistribution</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zones</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zone</span>: <span class="lg-highlight-string">"zone04"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <!-- -->{ <span class="lg-highlight-attr">region_id</span>: <span class="lg-highlight-title lg-highlight-class">MinKey</span>(<!-- -->) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <!-- -->{ <span class="lg-highlight-attr">region_id</span>: <span class="lg-highlight-number">10</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">zone</span>: <span class="lg-highlight-string">"zone05"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <!-- -->{ <span class="lg-highlight-attr">region_id</span>: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <!-- -->{ <span class="lg-highlight-attr">region_id</span>: <span class="lg-highlight-title lg-highlight-class">MaxKey</span>(<!-- -->) }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">})</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/query/near/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$near
<a class="headerlink leafygreen-ui-1kepx47" href="#-near" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-near">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="query">
<dt>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-query-op.-near" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-query-op.-near">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Specifies a point for which a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-geospatial">
geospatial
</a>
query returns the
documents from nearest to farthest. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
operator can
specify either a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-GeoJSON">
GeoJSON
</a>
point or legacy coordinate point.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
requires a geospatial index:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index">
2dsphere
</a>
index if specifying a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-GeoJSON">
GeoJSON
</a>
point.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
2d
</a>
index if specifying a point using legacy
coordinates.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To specify a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-GeoJSON">
GeoJSON
</a>
point,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
operator requires
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index">
2dsphere
</a>
index and has the following
syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n <location>: {\n $near: {\n $geometry: {\n type: \"Point\" ,\n coordinates: [ <longitude> , <latitude> ]\n },\n $maxDistance: <distance>,\n $minDistance: <distance>\n }\n }\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- --><location field>: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> $near: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> $geometry: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> type: "Point" ,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> coordinates: [ <longitude> , <latitude> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> $maxDistance: <distance in meters>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> $minDistance: <distance in meters></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If specifying latitude and longitude coordinates, list the
<strong>
longitude
</strong>
first, and then
<strong>
latitude
</strong>
.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Valid longitude values are between
<code class="leafygreen-ui-1l06pbn">
-180
</code>
and
<code class="leafygreen-ui-1l06pbn">
180
</code>
, both
inclusive.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Valid latitude values are between
<code class="leafygreen-ui-1l06pbn">
-90
</code>
and
<code class="leafygreen-ui-1l06pbn">
90
</code>
, both
inclusive.
</p>
</li>
</ul>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When specifying a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-GeoJSON">
GeoJSON
</a>
point, you can use the
<em>
optional
</em>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/minDistance/#mongodb-query-op.-minDistance">
<code class="leafygreen-ui-1l06pbn">
$minDistance
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/maxDistance/#mongodb-query-op.-maxDistance">
<code class="leafygreen-ui-1l06pbn">
$maxDistance
</code>
</a>
specifications to
limit the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
results by distance in
<em>
meters
</em>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/minDistance/#mongodb-query-op.-minDistance">
<code class="leafygreen-ui-1l06pbn">
$minDistance
</code>
</a>
limits the results to those documents that
are
<em>
at least
</em>
the specified distance from the center point.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/maxDistance/#mongodb-query-op.-maxDistance">
<code class="leafygreen-ui-1l06pbn">
$maxDistance
</code>
</a>
limits the results to those documents that
are
<em>
at most
</em>
the specified distance from the center point.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To specify a point using legacy coordinates,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
requires
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
2d
</a>
index and has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n $near: [ <x>, <y> ],\n $maxDistance: <distance>\n}","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$near</span>: <!-- -->[ <<!-- -->x<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->y<!-- -->> <!-- -->]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$maxDistance</span>: <span class="lg-highlight-tag lg-highlight-xml"><</span><span class="lg-highlight-name lg-highlight-tag lg-highlight-xml">distance</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">in</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">radians</span><span class="lg-highlight-tag lg-highlight-xml">></span><span class="lg-highlight-xml"></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-xml">}</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When specifying a legacy coordinate, you can use the
<em>
optional
</em>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/maxDistance/#mongodb-query-op.-maxDistance">
<code class="leafygreen-ui-1l06pbn">
$maxDistance
</code>
</a>
specification to limit the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
results by distance in
<em>
radians
</em>
.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/maxDistance/#mongodb-query-op.-maxDistance">
<code class="leafygreen-ui-1l06pbn">
$maxDistance
</code>
</a>
limits the
results to those documents that are
<em>
at most
</em>
the specified distance
from the center point.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Special Indexes Restriction
<a class="headerlink leafygreen-ui-1kepx47" href="#special-indexes-restriction" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="special-indexes-restriction">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You cannot combine the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
operator, which requires a
special
<a class="leafygreen-ui-tqgtui" href="/docs/manual/geospatial-queries/#std-label-index-feature-geospatial">
geospatial index
</a>
, with a
query operator or command that requires another special index. For
example you cannot combine
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/text/#mongodb-query-op.-text">
<code class="leafygreen-ui-1l06pbn">
$text
</code>
</a>
query.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Sort Operation
<a class="headerlink leafygreen-ui-1kepx47" href="#sort-operation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sort-operation">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
operator sorts documents by distance.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#mongodb-method-cursor.sort">
<code class="leafygreen-ui-1l06pbn">
sort()
</code>
</a>
method in your query,
MongoDB performs a second sort operation, re-ordering the matching
documents. When querying large collections, this can negatively
affect query performance.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the order of the documents is not important to you, consider
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
<code class="leafygreen-ui-1l06pbn">
$geoWithin
</code>
</a>
operator instead, as it returns
unsorted results.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
is a Match Execution operator and is not
permitted in aggregation pipelines.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Validation
<a class="headerlink leafygreen-ui-1kepx47" href="#validation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="validation">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-near" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$near
</code>
</span>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
<code class="leafygreen-ui-1l06pbn">
$nearSphere
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
<code class="leafygreen-ui-1l06pbn">
$geoNear
</code>
</a>
validate that the type of the specified
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geojson-point">
GeoJSON points
</a>
is
<code class="leafygreen-ui-1l06pbn">
Point
</code>
. Any other input
type returns an error.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="examples">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query on GeoJSON Data
<a class="headerlink leafygreen-ui-1kepx47" href="#query-on-geojson-data" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="query-on-geojson-data">
</div>
</a>
</h3>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If specifying latitude and longitude coordinates, list the
<strong>
longitude
</strong>
first, and then
<strong>
latitude
</strong>
.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Valid longitude values are between
<code class="leafygreen-ui-1l06pbn">
-180
</code>
and
<code class="leafygreen-ui-1l06pbn">
180
</code>
, both
inclusive.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Valid latitude values are between
<code class="leafygreen-ui-1l06pbn">
-90
</code>
and
<code class="leafygreen-ui-1l06pbn">
90
</code>
, both
inclusive.
</p>
</li>
</ul>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Consider a collection
<code class="leafygreen-ui-1l06pbn">
places
</code>
that has a
<code class="leafygreen-ui-1l06pbn">
2dsphere
</code>
index.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example returns documents that are at least
<code class="leafygreen-ui-1l06pbn">
1000
</code>
meters from and at most
<code class="leafygreen-ui-1l06pbn">
5000
</code>
meters from the specified GeoJSON
point, sorted from nearest to farthest:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.places.find(\n {\n location:\n { $near :\n {\n $geometry: { type: \"Point\", coordinates: [ -73.9667, 40.78 ] },\n $minDistance: 1000,\n $maxDistance: 5000\n }\n }\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">places</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">location</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->$near<!-- --> <!-- -->:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$geometry</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9667</span>, <span class="lg-highlight-number">40.78</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$minDistance</span>: <span class="lg-highlight-number">1000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$maxDistance</span>: <span class="lg-highlight-number">5000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query on Legacy Coordinates
<a class="headerlink leafygreen-ui-1kepx47" href="#query-on-legacy-coordinates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="query-on-legacy-coordinates">
</div>
</a>
</h3>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If specifying latitude and longitude coordinates, list the
<strong>
longitude
</strong>
first, and then
<strong>
latitude
</strong>
.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Valid longitude values are between
<code class="leafygreen-ui-1l06pbn">
-180
</code>
and
<code class="leafygreen-ui-1l06pbn">
180
</code>
, both
inclusive.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Valid latitude values are between
<code class="leafygreen-ui-1l06pbn">
-90
</code>
and
<code class="leafygreen-ui-1l06pbn">
90
</code>
, both
inclusive.
</p>
</li>
</ul>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Consider a collection
<code class="leafygreen-ui-1l06pbn">
legacy2d
</code>
that has a
<code class="leafygreen-ui-1l06pbn">
2d
</code>
index.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example returns documents that are at most
<code class="leafygreen-ui-1l06pbn">
0.10
</code>
radians from the specified legacy coordinate pair, sorted from nearest
to farthest:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.legacy2d.find(\n { location : { $near : [ -73.9667, 40.78 ], $maxDistance: 0.10 } }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">legacy2d</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->location <!-- -->: <!-- -->{ <!-- -->$near<!-- --> <!-- -->: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9667</span>, <span class="lg-highlight-number">40.78</span> ]<!-- -->, <span class="lg-highlight-attr">$maxDistance</span>: <span class="lg-highlight-number">0.10</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/renameCollection/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
renameCollection
<a class="headerlink leafygreen-ui-1kepx47" href="#renamecollection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="renamecollection">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
<span>
Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self">
<span>
Command Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.renameCollection" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-dbcommand-dbcmd.renameCollection">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Changes the name of an existing collection. Specify collection names
to
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
in the form of a complete
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
namespace
</a>
(
<code class="leafygreen-ui-1l06pbn">
<database>.<collection>
</code>
).
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
In
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
, this command can also be run through the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.renameCollection/#mongodb-method-db.collection.renameCollection">
<code class="leafygreen-ui-1l06pbn">
renameCollection()
</code>
</a>
helper method
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
Helper methods are convenient for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
users, but they may not
return the same level of information as database commands. In cases where
the convenience is not needed or the additional return fields are required,
use the database command.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Issue the
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
command against the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-admin-database">
admin database
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This command is available in deployments hosted in the following environments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
: The fully
managed service for MongoDB deployments in the cloud
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
This command is supported in all MongoDB Atlas clusters.
For information on Atlas support for all commands, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
<span>
Unsupported Commands
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
MongoDB Enterprise
</a>
: The
subscription-based, self-managed version of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
MongoDB Community
</a>
: The
source-available, free-to-use, and self-managed version of MongoDB
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Syntax
<a class="headerlink leafygreen-ui-1kepx47" href="#syntax" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="syntax">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n renameCollection: \"<source_namespace>\",\n to: \"<target_namespace>\",\n dropTarget: <true|false>,\n writeConcern: <document>,\n comment: <any>\n }\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">renameCollection</span>: <span class="lg-highlight-string">"<source_namespace>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">to</span>: <span class="lg-highlight-string">"<target_namespace>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dropTarget</span>: <!-- --><true|false>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> writeConcern: <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> comment: <any></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Command Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="command-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The command contains the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:20%"/>
<col style="width:80%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Field
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
namespace
</a>
of the collection to rename. The namespace is a
combination of the database name and the name of the collection.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
to
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The new namespace of the collection. If the new namespace specifies a
different database, the
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
command copies
the collection to the new database and drops the source collection.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#std-label-restrictions-on-db-names">
Naming Restrictions
<!-- -->
.
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
dropTarget
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. If
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
will drop the
<code class="leafygreen-ui-1l06pbn">
target
</code>
of
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
prior to renaming the collection. The
default value is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
writeConcern
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. A document that expresses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
for the operation. Omit to use the default write
concern.
</p>
<p class="leafygreen-ui-1kp3ins">
When issued on a sharded cluster,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
converts the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.renameCollection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
</span>
</a>
command and its helper
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.renameCollection/#mongodb-method-db.collection.renameCollection">
<code class="leafygreen-ui-1l06pbn">
db.collection.renameCollection()
</code>
</a>
to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
comment
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
any
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. A user-provided comment to attach to this command. Once set, this
comment appears alongside records of this command in the following
locations:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
mongod log messages
</a>
, in the
<code class="leafygreen-ui-1l06pbn">
attr.command.cursor.comment
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler">
Database profiler
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp">
<code class="leafygreen-ui-1l06pbn">
currentOp
</code>
</a>
output, in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.command">
<code class="leafygreen-ui-1l06pbn">
command.comment
</code>
</a>
field.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
A comment can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON type
</a>
(string, integer, object, array, etc).
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Sharded Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#sharded-collections" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sharded-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, you can use the
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
command to change the name of a sharded collection. The target
database must be the same as the source database.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Unsharded Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#unsharded-collections" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="unsharded-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can use
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
to rename an unsharded
collection in a sharded cluster as long as the source and target
databases have the same primary shard.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Time Series Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#time-series-collections" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="time-series-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You
<strong>
cannot
</strong>
use
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
to rename a time series
collection. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-limitations/#std-label-manual-timeseries-collection-limitations">
Time Series Collection Limitations
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Existing Target Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#existing-target-collection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="existing-target-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
fails if
<code class="leafygreen-ui-1l06pbn">
target
</code>
is the name of an existing
collection
<em>
and
</em>
you do not specify
<code class="leafygreen-ui-1l06pbn">
dropTarget: true
</code>
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Performance
<a class="headerlink leafygreen-ui-1kepx47" href="#performance" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="performance">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
has different performance implications depending
on the target
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
namespace
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If the target database is the same as the source database,
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
simply changes the namespace. This is a
quick operation.
</p>
<p class="leafygreen-ui-1kp3ins">
If the target database differs from the source database,
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
copies all documents from the source
collection to the target collection. Depending on the size of the
collection, this may take longer to complete.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Resource Locking in Sharded Clusters
<a class="headerlink leafygreen-ui-1kepx47" href="#resource-locking-in-sharded-clusters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="resource-locking-in-sharded-clusters">
</div>
</a>
</h3>
<div>
<p>
<em>
Changed
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
When renaming a sharded or unsharded collection in a sharded cluster,
the source and target collections are exclusively locked on every shard.
Subsequent operations on the source and target collections must wait
until the rename operation completes.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on locking in MongoDB, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/faq/concurrency/">
FAQ: Concurrency
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Resource Locking in Replica Sets
<a class="headerlink leafygreen-ui-1kepx47" href="#resource-locking-in-replica-sets" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="resource-locking-in-replica-sets">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If renaming a collection within the same database,
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
obtains an exclusive lock on
the source and target collections for the duration of the operation.
All subsequent operations on the collections must wait until
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
completes.
</p>
<p class="leafygreen-ui-1kp3ins">
If renaming a collection between different databases,
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
obtains an exclusive (W) lock on the target
database, an intent shared (r) lock on the source database, and a shared (S)
lock on the source collection. Subsequent operations on the target database
must wait until
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
releases the exclusive database
lock.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on locking in MongoDB, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/faq/concurrency/">
FAQ: Concurrency
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
local
</code>
Database
<a class="headerlink leafygreen-ui-1kepx47" href="#local-database" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="local-database">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot rename a collection from a replicated database to the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database, which is not replicated.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot rename a collection from the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database, which is
not replicated, to a replicated database.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Open Cursors and Change Streams
<a class="headerlink leafygreen-ui-1kepx47" href="#open-cursors-and-change-streams" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="open-cursors-and-change-streams">
</div>
</a>
</h3>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.renameCollection/#mongodb-method-db.collection.renameCollection">
<code class="leafygreen-ui-1l06pbn">
db.collection.renameCollection()
</code>
</a>
method and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.renameCollection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
</span>
</a>
command invalidate open cursors. This creates
an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/change-events/invalidate/#std-label-change-event-invalidate">
invalidate event
</a>
for any existing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change streams
</a>
opened on the source or target
collection, and also interrupts queries that are currently returning
data from the renamed collection.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Interaction with
<code class="leafygreen-ui-1l06pbn">
mongodump
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#interaction-with-mongodump" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="interaction-with-mongodump">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
A
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongodump
</code>
</span>
</a>
started with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#std-option-mongodump.--oplog" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
--oplog
</code>
</span>
</a>
fails if a client issues the
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
command during the
dump process. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongodump/#std-option-mongodump.--oplog" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongodump.--oplog
</code>
</span>
</a>
for more information.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following example renames a collection named
<code class="leafygreen-ui-1l06pbn">
orders
</code>
in the
<code class="leafygreen-ui-1l06pbn">
test
</code>
database to
<code class="leafygreen-ui-1l06pbn">
orders2014
</code>
in the
<code class="leafygreen-ui-1l06pbn">
test
</code>
database.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { renameCollection: \"test.orders\", to: \"test.orders2014\" } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">renameCollection</span>: <span class="lg-highlight-string">"test.orders"</span>, <span class="lg-highlight-attr">to</span>: <span class="lg-highlight-string">"test.orders2014"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
provides the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.renameCollection/#mongodb-method-db.collection.renameCollection">
<code class="leafygreen-ui-1l06pbn">
db.collection.renameCollection()
</code>
</a>
helper for the command to
rename collections within the
<em>
same
</em>
database. The following is
equivalent to the previous example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use test\ndb.orders.renameCollection( \"orders2014\" )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use test</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">orders</span>.<span class="lg-highlight-title lg-highlight-function">renameCollection</span>( <span class="lg-highlight-string">"orders2014"</span> )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$floor (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-floor--aggregation-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-floor--aggregation-">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#definition" target="_self">
<span>
Definition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
<span>
Behavior
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Definition
<a class="headerlink leafygreen-ui-1kepx47" href="#definition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="definition">
</div>
</a>
</h2>
<dl class="expression">
<dt>
<code class="leafygreen-ui-1l06pbn">
$floor
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-floor" title="Permalink to this definition">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongodb-expression-exp.-floor">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns the largest integer less than or equal to the specified
number.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-floor" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$floor
</code>
</span>
</a>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $floor: <number> }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$floor</span>: <<!-- -->number<!-- -->> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
<number>
</code>
expression can be any valid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
as long as it resolves to a number. For
more information on expressions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
<!-- -->
.
</a>
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="behavior">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If the argument resolves to a value of
<code class="leafygreen-ui-1l06pbn">
null
</code>
or refers to a field that is
missing,
<code class="leafygreen-ui-1l06pbn">
$floor
</code>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
. If the argument resolves to
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
,
<code class="leafygreen-ui-1l06pbn">
$floor
</code>
returns
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:85%"/>
<col style="width:15%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Example
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Results
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $floor: 1 }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
1
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $floor: 7.80 }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
7
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $floor: -2.8 }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
-3
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Create a collection named
<code class="leafygreen-ui-1l06pbn">
samples
</code>
with the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.samples.insertMany(\n [\n { _id: 1, value: 9.25 },\n { _id: 2, value: 8.73 },\n { _id: 3, value: 4.32 },\n { _id: 4, value: -5.34 }\n ]\n)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">samples</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">9.25</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">8.73</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">4.32</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">value</span>: <!-- -->-<span class="lg-highlight-number">5.34</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example returns both the original value and the floor
value:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.samples.aggregate([\n { $project: { value: 1, floorValue: { $floor: \"$value\" } } }\n])","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">samples</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">floorValue</span>: <!-- -->{ <span class="lg-highlight-attr">$floor</span>: <span class="lg-highlight-string">"$value"</span> } } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the following results:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"value\" : 9.25, \"floorValue\" : 9 }\n{ \"_id\" : 2, \"value\" : 8.73, \"floorValue\" : 8 }\n{ \"_id\" : 3, \"value\" : 4.32, \"floorValue\" : 4 }\n{ \"_id\" : 4, \"value\" : -5.34, \"floorValue\" : -6 }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">9.25</span>, <span class="lg-highlight-string">"floorValue"</span> <!-- -->: <span class="lg-highlight-number">9</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">8.73</span>, <span class="lg-highlight-string">"floorValue"</span> <!-- -->: <span class="lg-highlight-number">8</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">4.32</span>, <span class="lg-highlight-string">"floorValue"</span> <!-- -->: <span class="lg-highlight-number">4</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->-<span class="lg-highlight-number">5.34</span>, <span class="lg-highlight-string">"floorValue"</span> <!-- -->: <!-- -->-<span class="lg-highlight-number">6</span> }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/control-access-to-mongodb-with-kerberos-authentication/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Configure Self-Managed MongoDB with Kerberos Authentication on Linux
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-self-managed-mongodb-with-kerberos-authentication-on-linux" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configure-self-managed-mongodb-with-kerberos-authentication-on-linux">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#prerequisites" target="_self">
<span>
Prerequisites
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#procedure" target="_self">
<span>
Procedure
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-considerations" target="_self">
<span>
Additional Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#testing-and-verification" target="_self">
<span>
Testing and Verification
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB Enterprise supports authentication using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/">
Kerberos
service
</a>
. Kerberos is an industry standard
authentication protocol for large client/server systems. MongoDB
Enterprise only supports the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://kerberos.org/" rel="noopener noreferrer">
<span>
MIT implementation
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
of Kerberos.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-kerberos-linux-prerequisites">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Prerequisites
<a class="headerlink leafygreen-ui-1kepx47" href="#prerequisites" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="prerequisites">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To verify that you are using MongoDB Enterprise, pass the
<code class="leafygreen-ui-1l06pbn">
--version
</code>
command line option to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --version","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongod --version</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In the output from this command, look for the string
<code class="leafygreen-ui-1l06pbn">
modules:
subscription
</code>
or
<code class="leafygreen-ui-1l06pbn">
modules: enterprise
</code>
to confirm you are using the
MongoDB Enterprise binaries.
</p>
<p class="leafygreen-ui-1kp3ins">
For replica sets and sharded clusters, ensure that your configuration
uses fully qualified domain names (FQDN) rather than IP addresses or
unqualified hostnames. You must use the FQDN for GSSAPI to correctly
resolve the Kerberos realms and allow you to connect.
</p>
<p class="leafygreen-ui-1kp3ins">
Setting up and configuring a Kerberos deployment is beyond the scope of
this document. Please refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://web.mit.edu/kerberos/krb5-latest/doc/" rel="noopener noreferrer">
<span>
MIT Kerberos documentation
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
or your operating
system documentation for information on how to configure a Kerberos
deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
In order to use MongoDB with Kerberos, a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-kerberos-service-principal">
Kerberos service principal
</a>
for each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance in your MongoDB
deployment must be
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://web.mit.edu/kerberos/krb5-latest/doc/admin/database.html#add-principal" rel="noopener noreferrer">
<span>
added to the Kerberos database
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
.
You can add the service principal by running a command similar to the
following on your KDC:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"kadmin.local addprinc mongodb/[email protected]","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">kadmin.local addprinc mongodb<!-- -->/m<!-- -->[email protected]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
On each system running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
,
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
keytab file
</a>
must be
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://web.mit.edu/kerberos/krb5-latest/doc/admin/appl_servers.html#keytabs" rel="noopener noreferrer">
<span>
created
</span>
<svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
</path>
<path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
</path>
</svg>
</a>
for the respective service principal. You can create the keytab file by
running a command similar to the following on the system running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"kadmin.local ktadd mongodb/[email protected]","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">kadmin.local ktadd mongodb<!-- -->/m<!-- -->[email protected]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Procedure
<a class="headerlink leafygreen-ui-1kepx47" href="#procedure" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="procedure">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following procedure outlines the steps to add a Kerberos user
principal to MongoDB, configure a standalone
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance
for Kerberos support, and connect using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
and
authenticate the user principal.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start mongod without Kerberos.For the initial addition of Kerberos users, start mongod\nwithout Kerberos support.If a Kerberos user is already in MongoDB and has the\nprivileges required to create a user, you can start\nmongod with Kerberos support.Include additional settings as appropriate to your deployment.mongod and mongos\nbind to localhost by default. If the members of your deployment are\nrun on different hosts or if you wish remote clients to connect to\nyour deployment, you must specify --bind_ip or\nnet.bindIp."},{"@type":"HowToStep","text":"Connect to mongod.Connect mongosh to the mongod\ninstance. If mongod has --auth enabled, ensure\nyou connect with the privileges required to create a user."},{"@type":"HowToStep","text":"Add Kerberos Principal(s) to MongoDB.Add a Kerberos principal, <username>@<KERBEROS REALM> or\n<username>/<instance>@<KERBEROS REALM>, to MongoDB in the\n$external database. Specify the Kerberos realm in all uppercase.\nThe $external database allows mongod to consult an\nexternal source (e.g. Kerberos) to authenticate. To specify the\nuser's privileges, assign roles to the\nuser.To use Client Sessions and Causal Consistency Guarantees with $external authentication users\n(Kerberos, LDAP, or x.509 users), usernames cannot be greater\nthan 10k bytes.The following example adds the Kerberos principal\napplication/[email protected] with read-only access to the\nrecords database:Add additional principals as needed. For every user you want to\nauthenticate using Kerberos, you must create a corresponding user in\nMongoDB.\nFor more\ninformation about creating and managing users, see\nUser Management Commands."},{"@type":"HowToStep","text":"Start mongod with Kerberos support.To start mongod with Kerberos support, set the\nenvironmental variable KRB5_KTNAME to the path of the keytab\nfile and the mongod parameter\nauthenticationMechanisms to GSSAPI in the\nfollowing form:Include additional options as required for your configuration. For\ninstance, if you wish remote clients to connect to your deployment\nor your deployment members are run on different hosts, specify the\n--bind_ip.For example, the following starts a standalone mongod\ninstance with Kerberos support:The path to your mongod as well as your keytab file may differ. The keytab file\nmust be only accessible to the owner of the mongod\nprocess.With the official .deb or .rpm packages, you can set the\nKRB5_KTNAME in a environment settings file. See\nKRB5_KTNAME for details."},{"@type":"HowToStep","text":"Connect mongosh to mongod and authenticate.Connect mongosh client as the Kerberos principal\napplication/[email protected]. Before connecting, you\nmust have used Kerberos's kinit program to get credentials for\napplication/[email protected] can connect and authenticate from the command line.If you are connecting to a system whose hostname matches the\nKerberos name, ensure that you specify the fully qualified\ndomain name (FQDN) for the --host\noption, rather than an IP address or unqualified hostname.If you are connecting to a system whose hostname does not\nmatch the Kerberos name, first connect mongosh\nto the mongod, and then from\nmongosh, use the db.auth() method to\nauthenticate in the $external database."}],"name":"Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Start
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
without Kerberos.
<a class="headerlink leafygreen-ui-1kepx47" href="#start-mongod-without-kerberos" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="start-mongod-without-kerberos">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For the initial addition of Kerberos users, start
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
without Kerberos support.
</p>
<p class="leafygreen-ui-1kp3ins">
If a Kerberos user is already in MongoDB and has the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/createUser/#std-label-createUser-required-access">
privileges required to create a user
</a>
, you can start
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
with Kerberos support.
</p>
<p class="leafygreen-ui-1kp3ins">
Include additional settings as appropriate to your deployment.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
bind to localhost by default. If the members of your deployment are
run on different hosts or if you wish remote clients to connect to
your deployment, you must specify
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
.
</a>
</p>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Connect to
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#connect-to-mongod" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="connect-to-mongod">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance. If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
has
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--auth">
<code class="leafygreen-ui-1l06pbn">
--auth
</code>
</a>
enabled, ensure
you connect with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/createUser/#std-label-createUser-required-access">
privileges required to create a user
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Add Kerberos Principal(s) to MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#add-kerberos-principal-s-to-mongodb" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="add-kerberos-principal-s-to-mongodb">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Add a Kerberos principal,
<code class="leafygreen-ui-1l06pbn">
<username>@<KERBEROS REALM>
</code>
or
<code class="leafygreen-ui-1l06pbn">
<username>/<instance>@<KERBEROS REALM>
</code>
, to MongoDB in the
<code class="leafygreen-ui-1l06pbn">
$external
</code>
database. Specify the Kerberos realm in all uppercase.
The
<code class="leafygreen-ui-1l06pbn">
$external
</code>
database allows
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
to consult an
external source (e.g. Kerberos) to authenticate. To specify the
user's privileges, assign
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
roles
</a>
to the
user.
</p>
<p class="leafygreen-ui-1kp3ins">
To use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions">
Client Sessions and Causal Consistency Guarantees
</a>
with
<code class="leafygreen-ui-1l06pbn">
$external
</code>
authentication users
(Kerberos, LDAP, or x.509 users), usernames cannot be greater
than 10k bytes.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example adds the Kerberos principal
<code class="leafygreen-ui-1l06pbn">
application/[email protected]
</code>
with read-only access to the
<code class="leafygreen-ui-1l06pbn">
records
</code>
database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use $external\ndb.createUser(\n {\n user: \"application/[email protected]\",\n roles: [ { role: \"read\", db: \"records\" } ]\n }\n)\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use <!-- -->$external</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">createUser</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"application/[email protected]"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">roles</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"read"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"records"</span> } ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Add additional principals as needed. For every user you want to
authenticate using Kerberos, you must create a corresponding user in
MongoDB.
For more
information about creating and managing users, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/nav-user-management/">
User Management Commands
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Start
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
with Kerberos support.
<a class="headerlink leafygreen-ui-1kepx47" href="#start-mongod-with-kerberos-support" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="start-mongod-with-kerberos-support">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To start
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
with Kerberos support, set the
environmental variable
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
to the path of the keytab
file and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
parameter
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.authenticationMechanisms">
<code class="leafygreen-ui-1l06pbn">
authenticationMechanisms
</code>
</a>
to
<code class="leafygreen-ui-1l06pbn">
GSSAPI
</code>
in the
following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"env KRB5_KTNAME=<path> \\\nmongod \\\n--setParameter authenticationMechanisms=GSSAPI \\\n<additional>\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">env KRB5_KTNAME=<path to keytab file> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongod \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--setParameter authenticationMechanisms=GSSAPI \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><additional mongod options></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include additional options as required for your configuration. For
instance, if you wish remote clients to connect to your deployment
or your deployment members are run on different hosts, specify the
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following starts a standalone
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance with Kerberos support:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"env KRB5_KTNAME=/opt/mongodb/mongod.keytab \\\n/opt/mongodb/bin/mongod --auth \\\n--setParameter authenticationMechanisms=GSSAPI \\\n--dbpath /opt/mongodb/data --bind_ip localhost,<hostname(s)|ip>\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">env KRB5_KTNAME=/opt/mongodb/mongod.keytab \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">/opt/mongodb/bin/mongod --auth \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--setParameter authenticationMechanisms=GSSAPI \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--dbpath /opt/mongodb/data --bind_ip localhost,<hostname(s)|ip address(es)></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The path to your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
as well as your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
keytab file
</a>
may differ. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
keytab file
</a>
must be only accessible to the owner of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process.
</p>
<p class="leafygreen-ui-1kp3ins">
With the official
<code class="leafygreen-ui-1l06pbn">
.deb
</code>
or
<code class="leafygreen-ui-1l06pbn">
.rpm
</code>
packages, you can set the
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
in a environment settings file. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-setting-krb5_ktname" target="_self">
<span>
KRB5_KTNAME
</span>
</a>
for details.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
5
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Connect
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
to
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
and authenticate.
<a class="headerlink leafygreen-ui-1kepx47" href="#connect-mongosh-to-mongod-and-authenticate" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="connect-mongosh-to-mongod-and-authenticate">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
client as the Kerberos principal
<code class="leafygreen-ui-1l06pbn">
application/[email protected]
</code>
. Before connecting, you
must have used Kerberos's
<code class="leafygreen-ui-1l06pbn">
kinit
</code>
program to get credentials for
<code class="leafygreen-ui-1l06pbn">
application/[email protected]
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
You can connect and authenticate from the command line.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongosh --host hostname.example.net --authenticationMechanism=GSSAPI --authenticationDatabase='$external' --username application/[email protected]\n","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh --host hostname.example.net --authenticationMechanism=GSSAPI --authenticationDatabase='$external' --username application/[email protected]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you are connecting to a system whose hostname matches the
Kerberos name, ensure that you specify the fully qualified
domain name (FQDN) for the
<code class="leafygreen-ui-1l06pbn">
--host
</code>
option, rather than an IP address or unqualified hostname.
</p>
<p class="leafygreen-ui-1kp3ins">
If you are connecting to a system whose hostname does not
match the Kerberos name, first connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
, and then from
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.auth/#mongodb-method-db.auth">
<code class="leafygreen-ui-1l06pbn">
db.auth()
</code>
</a>
method to
authenticate in the
<code class="leafygreen-ui-1l06pbn">
$external
</code>
database.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use $external\ndb.auth( { mechanism: \"GSSAPI\", user: \"application/[email protected]\" } )\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">use <!-- -->$external</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">auth</span>( <!-- -->{ <span class="lg-highlight-attr">mechanism</span>: <span class="lg-highlight-string">"GSSAPI"</span>, <span class="lg-highlight-attr">user</span>: <span class="lg-highlight-string">"application/[email protected]"</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-considerations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="additional-considerations">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-setting-krb5_ktname">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
KRB5_KTNAME
<a class="headerlink leafygreen-ui-1kepx47" href="#krb5_ktname" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="krb5_ktname">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you installed MongoDB Enterprise using one of the official
<code class="leafygreen-ui-1l06pbn">
.deb
</code>
or
<code class="leafygreen-ui-1l06pbn">
.rpm
</code>
packages, and you use the included init/upstart scripts to
control the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance, you can set the
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
variable in the default environment settings file instead of setting
the variable each time.
</p>
<p class="leafygreen-ui-1kp3ins">
Recent versions of Red Hat and Debian-based systems use
<code class="leafygreen-ui-1l06pbn">
systemd
</code>
.
Older versions use
<code class="leafygreen-ui-1l06pbn">
init
</code>
for system initialization. Follow the
appropriate instructions to configure the
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
variable for
your system.
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
systemd
</code>
Configuration Files
<a class="headerlink leafygreen-ui-1kepx47" href="#systemd-configuration-files" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="systemd-configuration-files">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
systemd
</code>
stores configuration in unit files. Update the unit file to
set the
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
variable.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"The systemctl command returns the file location and displays its\ncontents.","name":"Find the unit file"},{"@type":"HowToStep","text":"To set the KRB5_KTNAME variable, edit the following line to reflect\nthe location of your keytab file:","name":"Set KRB5_KTNAME"},{"@type":"HowToStep","text":"Add the edited line to the unit file. The edited unit file will\nresemble:","name":"Edit the unit file"},{"@type":"HowToStep","text":"Reload the updated unit file:"},{"@type":"HowToStep","text":"Restart the mongod service"}],"name":"systemd Configuration Files","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Find the unit file
<a class="headerlink leafygreen-ui-1kepx47" href="#find-the-unit-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="find-the-unit-file">
</div>
</a>
</h5>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl cat mongod","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl cat mongod</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
systemctl
</code>
command returns the file location and displays its
contents.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Set
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#set-krb5_ktname" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="set-krb5_ktname">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
To set the
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
variable, edit the following line to reflect
the location of your
<code class="leafygreen-ui-1l06pbn">
keytab
</code>
file:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Environment=\"KRB5_KTNAME=<path-to-your-mongod.keytab-file>\"","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">Environment="KRB5_KTNAME=<path-to-your-mongod.keytab-file>"</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Edit the unit file
<a class="headerlink leafygreen-ui-1kepx47" href="#edit-the-unit-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="edit-the-unit-file">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
Add the edited line to the unit file. The edited unit file will
resemble:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[Unit]\nDescription=High-performance, schema-free document-oriented database\nAfter=network.target\nDocumentation=https://docs.mongodb.org/manual\n\n[Service]\nUser=mongodb\nGroup=mongodb\nExecStart=/usr/bin/mongod --config /etc/mongod.conf\nEnvironment=\"KRB5_KTNAME=/etc/mongod.keytab\"\nPIDFile=/var/run/mongodb/mongod.pid\n# file size\nLimitFSIZE=infinity\n# cpu time\nLimitCPU=infinity\n# virtual memory size\nLimitAS=infinity\n# open files\nLimitNOFILE=64000\n# processes/threads\nLimitNPROC=64000\n# locked memory\nLimitMEMLOCK=infinity\n# total threads (user+kernel)\nTasksMax=infinity\nTasksAccounting=false\n\n# Recommended limits for for mongod as specified in\n# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings\n\n[Install]\nWantedBy=multi-user.target","programmingLanguage":"Shell"}
</script>
<div class="css-1lju8ps">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-tyg50d">
<pre class="leafygreen-ui-1453az5" tabindex="0"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">[Unit]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">Description=High-performance, schema-free document-oriented database</td></tr><tr class=""><td class="leafygreen-ui-7razhx">After=network.target</td></tr><tr class=""><td class="leafygreen-ui-7razhx">Documentation=https://docs.mongodb.org/manual</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[Service]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">User=mongodb</td></tr><tr class=""><td class="leafygreen-ui-7razhx">Group=mongodb</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">ExecStart=/usr/bin/mongod --config /etc/mongod.conf</td></tr><tr class=""><td class="leafygreen-ui-7razhx">Environment="KRB5_KTNAME=/etc/mongod.keytab"</td></tr><tr class=""><td class="leafygreen-ui-7razhx">PIDFile=/var/run/mongodb/mongod.pid</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">file size</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">LimitFSIZE=infinity</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">cpu time</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">LimitCPU=infinity</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">virtual memory size</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">LimitAS=infinity</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">open files</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">LimitNOFILE=64000</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">processes</span><span class="lg-highlight-bash">/threads</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">LimitNPROC=64000</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">locked memory</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">LimitMEMLOCK=infinity</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">total threads (user+kernel)</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">TasksMax=infinity</td></tr><tr class=""><td class="leafygreen-ui-7razhx">TasksAccounting=false</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">Recommended limits </span><span class="lg-highlight-keyword lg-highlight-bash">for</span><span class="lg-highlight-bash"> </span><span class="lg-highlight-keyword lg-highlight-bash">for</span><span class="lg-highlight-bash"> mongod as specified </span><span class="lg-highlight-keyword lg-highlight-bash">in</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-meta lg-highlight-prompt"># </span><span class="lg-highlight-bash">http:/</span><span class="lg-highlight-bash">/docs.mongodb.org/manual/reference/ulimit</span><span class="lg-highlight-bash">/</span><span class="lg-highlight-comment lg-highlight-bash">#recommended-settings</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[Install]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">WantedBy=multi-user.target</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Reload the updated unit file:
<a class="headerlink leafygreen-ui-1kepx47" href="#reload-the-updated-unit-file-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="reload-the-updated-unit-file-">
</div>
</a>
</h5>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl daemon-reload","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl daemon-reload</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
5
</div>
</div>
<div class="css-1ed38mk">
<section>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Restart the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
service
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-the--service" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-the--service">
</div>
</a>
</h5>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl restart mongod","programmingLanguage":"Shell"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light shell leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">sudo systemctl restart mongod</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
init
</code>
Configuration Files
<a class="headerlink leafygreen-ui-1kepx47" href="#init-configuration-files" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="init-configuration-files">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
For
<code class="leafygreen-ui-1l06pbn">
.rpm
</code>
installations, the default environment settings file is
<code class="file docutils literal">
<span class="pre">
/etc/sysconfig/mongod
</span>
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For
<code class="leafygreen-ui-1l06pbn">
.deb
</code>
installations, the file is
<code class="file docutils literal">
<span class="pre">
/etc/default/mongodb
</span>
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Set the
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
value by adding a line that resembles the
following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"KRB5_KTNAME=\"<path>\"","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">KRB5</span>_KTNAME<!-- -->=<span class="lg-highlight-string">"<path to keytab>"</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Configure
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
for Kerberos
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-mongos-for-kerberos" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configure-mongos-for-kerberos">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To start
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
with Kerberos support, set the environmental
variable
<code class="leafygreen-ui-1l06pbn">
KRB5_KTNAME
</code>
to the path of its
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
keytab file
</a>
and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
parameter
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.authenticationMechanisms">
<code class="leafygreen-ui-1l06pbn">
authenticationMechanisms
</code>
</a>
to
<code class="leafygreen-ui-1l06pbn">
GSSAPI
</code>
in the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"env KRB5_KTNAME=<path> \\\nmongos \\\n--setParameter authenticationMechanisms=GSSAPI \\\n<additional>","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">env</span> KRB5_KTNAME=<path to keytab file> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongos \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--setParameter authenticationMechanisms=GSSAPI \</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><additional mongos options></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include additional options as required for your configuration. For
instance, if you wish remote clients to connect to your deployment
or your deployment members are run on different hosts, specify the
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following starts a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance with
Kerberos support:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"env KRB5_KTNAME=/opt/mongodb/mongos.keytab \\\nmongos \\\n--setParameter authenticationMechanisms=GSSAPI \\\n--configdb shard0.example.net, shard1.example.net,shard2.example.net \\\n--keyFile /opt/mongodb/mongos.keyfile \\\n--bind_ip localhost,<hostname(s)|ip>","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">env</span> KRB5_KTNAME=<!-- -->/opt/mongodb/mongos.keytab<!-- --> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongos \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--setParameter authenticationMechanisms=GSSAPI \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--configdb shard0.example.net, shard1.example.net,shard2.example.net \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--keyFile <!-- -->/opt/mongodb/mongos.keyfile<!-- --> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">--bind_ip localhost,<hostname(s)|ip address(es)></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The path to your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
as well as your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
keytab file
</a>
may differ. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
keytab file
</a>
must
be only accessible to the owner of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
process.
</p>
<p class="leafygreen-ui-1kp3ins">
Modify or include any additional
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
options as required
for your configuration. For example, instead of using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-option-mongos.--keyFile">
<code class="leafygreen-ui-1l06pbn">
--keyFile
</code>
</a>
for internal authentication of sharded cluster
members, you can use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-x509-member-authentication/#std-label-x509-internal-authentication">
x.509 member authentication
</a>
instead.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use a Config File
<a class="headerlink leafygreen-ui-1kepx47" href="#use-a-config-file" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="use-a-config-file">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To configure
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
for Kerberos
support using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
</a>
, specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.authenticationMechanisms">
<code class="leafygreen-ui-1l06pbn">
authenticationMechanisms
</code>
</a>
setting in the configuration file.
</p>
<p class="leafygreen-ui-1kp3ins">
If using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
YAML configuration file format
<!-- -->
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"setParameter:\n authenticationMechanisms: GSSAPI","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">setParameter:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">authenticationMechanisms:</span> <span class="lg-highlight-string">GSSAPI</span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Include additional options as required
for your configuration. For instance, if you wish remote clients to
connect to your deployment or your deployment members are run on
different hosts, specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</a>
setting.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, if
<code class="file docutils literal">
<span class="pre">
/opt/mongodb/mongod.conf
</span>
</code>
contains the following
configuration settings for a standalone
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n authorization: enabled\nsetParameter:\n authenticationMechanisms: GSSAPI\nstorage:\n dbPath: /opt/mongodb/data\nnet:\n bindIp: localhost,<hostname(s)|ip>","programmingLanguage":"YAML"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light yaml leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">security:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">authorization:</span> <span class="lg-highlight-string">enabled</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">setParameter:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">authenticationMechanisms:</span> <span class="lg-highlight-string">GSSAPI</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbPath:</span> <span class="lg-highlight-string">/opt/mongodb/data</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-string">localhost,<hostname(s)|ip</span> <span class="lg-highlight-string">address(es)></span></td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To start
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
with Kerberos support, use the following
form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"env KRB5_KTNAME=/opt/mongodb/mongod.keytab \\\n/opt/mongodb/bin/mongod --config /opt/mongodb/mongod.conf","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-built_in">env</span> KRB5_KTNAME=<!-- -->/opt/mongodb/mongod.keytab<!-- --> \</td></tr><tr class=""><td class="leafygreen-ui-7razhx">/opt/mongodb/bin/mongod<!-- --> --config <!-- -->/opt/mongodb/mongod.conf</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The path to your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
keytab file
</a>
,
and configuration file may differ. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
keytab file
</a>
must be only accessible to the owner
of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Troubleshoot Kerberos Setup for MongoDB
<a class="headerlink leafygreen-ui-1kepx47" href="#troubleshoot-kerberos-setup-for-mongodb" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="troubleshoot-kerberos-setup-for-mongodb">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you encounter problems when starting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
with Kerberos authentication, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/troubleshoot-kerberos/">
Troubleshoot Self-Managed Kerberos Authentication
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-enable-mixed-kerberos-and-cr">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Incorporate Additional Authentication Mechanisms
<a class="headerlink leafygreen-ui-1kepx47" href="#incorporate-additional-authentication-mechanisms" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="incorporate-additional-authentication-mechanisms">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Kerberos authentication (
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-security-auth-kerberos">
GSSAPI
</a>
(Kerberos))
can work alongside:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB's SCRAM authentication mechanism:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-scram/#std-label-authentication-scram">
SCRAM-SHA-1
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-scram/#std-label-authentication-scram">
SCRAM-SHA-256
</a>
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB's authentication mechanism for LDAP:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-security-auth-ldap">
PLAIN
</a>
(LDAP SASL)
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB's authentication mechanism for x.509:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-x.509/#std-label-security-auth-x509">
MONGODB-X509
<!-- -->
)
</a>
</p>
</li>
</ul>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Specify the mechanisms as follows:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"--setParameter authenticationMechanisms=GSSAPI,SCRAM-SHA-256","programmingLanguage":"Bash"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">--setParameter authenticationMechanisms=GSSAPI,SCRAM-SHA-256</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Only add the other mechanisms if in use. This parameter setting does
not affect MongoDB's internal authentication of cluster members.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Testing and Verification
<a class="headerlink leafygreen-ui-1kepx47" href="#testing-and-verification" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="testing-and-verification">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
After completing the configuration steps, you can validate your
configuration with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongokerberos/#mongodb-binary-bin.mongokerberos">
<code class="leafygreen-ui-1l06pbn">
mongokerberos
</code>
</a>
tool.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongokerberos/#mongodb-binary-bin.mongokerberos">
<code class="leafygreen-ui-1l06pbn">
mongokerberos
</code>
</a>
provides a convenient method to verify your
platform's Kerberos configuration for use with MongoDB, and to test that
Kerberos authentication from a MongoDB client works as expected. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongokerberos/#mongodb-binary-bin.mongokerberos">
<code class="leafygreen-ui-1l06pbn">
mongokerberos
</code>
</a>
documentation for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongokerberos/#mongodb-binary-bin.mongokerberos">
<code class="leafygreen-ui-1l06pbn">
mongokerberos
</code>
</a>
is available in MongoDB Enterprise only.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/read-concern/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Read Concern
<a class="headerlink leafygreen-ui-1kepx47" href="#read-concern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-concern">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#read-concern-levels" target="_self">
<span>
Read Concern Levels
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#readconcern-support" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
readConcern
</code>
Support
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self">
<span>
Considerations
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
readConcern
</code>
option allows you to control the consistency and
isolation properties of the data read from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication">
replica sets
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-background">
sharded clusters
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Through the effective use of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concerns
</a>
and read concerns, you can adjust the level
of consistency and availability guarantees as appropriate, such as
waiting for stronger consistency guarantees, or loosening consistency
requirements to provide higher availability.
</p>
<p class="leafygreen-ui-1kp3ins">
Replica sets and sharded clusters support setting a global default read concern.
Operations which do not specify an explicit read concern inherit the global
default read concern settings. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#mongodb-dbcommand-dbcmd.setDefaultRWConcern">
<code class="leafygreen-ui-1l06pbn">
setDefaultRWConcern
</code>
</a>
for
more information.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-read-concern-levels">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Read Concern Levels
<a class="headerlink leafygreen-ui-1kepx47" href="#read-concern-levels" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-concern-levels">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following read concern levels are available:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:10%"/>
<col style="width:90%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<code class="leafygreen-ui-1l06pbn">
level
</code>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The query returns data from the instance with no guarantee that
the data has been written to a majority of the replica set
members (i.e. may be rolled back).
</p>
<p class="leafygreen-ui-1kp3ins">
Default for reads against the primary and secondaries.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
Availability:
</strong>
Read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
is available
for use with or without causally consistent sessions and
transactions.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
reference
page.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The query returns data from the instance with no guarantee
that the data has been written to a majority of the replica set
members (i.e. may be rolled back).
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
Availability:
</strong>
Read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
is
<strong class="css-4dei7l">
unavailable for use
</strong>
with causally consistent sessions and
transactions.
</p>
<p class="leafygreen-ui-1kp3ins">
For sharded clusters,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
read concern
provides the lowest latency reads possible among the various
read concerns. However, this comes at the expense of consistency
as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
read concern can return
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document">
orphaned documents
</a>
when reading from
a sharded collection. To avoid the risk of returning orphaned
documents when reading from sharded collections, use a different
read concern such as read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
reference page.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The query returns the data that has been acknowledged by a
majority of the replica set members. The documents returned by
the read operation are durable, even in the event of failure.
</p>
<p class="leafygreen-ui-1kp3ins">
To fulfill read concern "majority", the replica set member
returns data from its in-memory view of the data at the
majority-commit point. As such, read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
is comparable in performance
cost to other read concerns.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
Availability:
</strong>
</p>
<p class="leafygreen-ui-1kp3ins">
Read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
is available for use with
or without causally consistent sessions and transactions.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
Requirements:
</strong>
To use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-read-concern">
read concern
</a>
level of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
, replica sets must use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger storage engine
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For operations in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
multi-document transactions
</a>
, read concern
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
provides
its guarantees only if the transaction commits with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern">
write concern "majority"
</a>
.
Otherwise, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
read concern
provides no guarantees about the data read in transactions.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
reference page.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The query returns data that reflects all successful
majority-acknowledged writes that completed prior to the start
of the read operation. The query may wait for concurrently
executing writes to propagate to a majority of replica
set members before returning results.
</p>
<p class="leafygreen-ui-1kp3ins">
If a majority of your replica set members crash and restart after
the read operation, documents returned by the read operation are
durable if
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault">
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</a>
is set to
the default state of
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
With
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault">
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
,
MongoDB does not wait for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
w: "majority"
</code>
</a>
writes to be written to the on-disk journal before acknowledging the
writes. As such,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
write operations could
possibly roll back in the event of a transient loss (e.g. crash and
restart) of a majority of nodes in a given replica set.
</p>
<dl>
<dt>
Availability:
</dt>
<dd class="css-1ufxuu7">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
is
<strong class="css-4dei7l">
unavailable for use
</strong>
with causally consistent
sessions and transactions.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can specify linearizable read concern for read
operations on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</a>
only.
</p>
</li>
</ul>
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
You cannot use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
stage
in conjunction with read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
. That
is, if you specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
read concern for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
db.collection.aggregate()
</code>
</a>
, you cannot include either
stages in the pipeline.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
Requirements:
</strong>
</p>
<p class="leafygreen-ui-1kp3ins">
Linearizable read concern guarantees only apply if read operations
specify a query filter that uniquely identifies a single document.
Additionally if none of the following criteria are met, linearizable
read concern might not read from a consistent snapshot, resulting in a
document matching the filter not being returned:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The query uses an immutable field as the search key of the query. For
example, searching on the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field or using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/meta/natural/#mongodb-operator-metaOp.-natural">
<code class="leafygreen-ui-1l06pbn">
$natural
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
No concurrent updates mutate the search key of the query.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The search key has a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
unique index
</a>
and the
query uses that index.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If any of the preceding criteria are met, the query reads from a
consistent snapshot to return the single matching document.
</p>
<p class="leafygreen-ui-1kp3ins">
Always use
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
with linearizable read concern in
case a majority of data bearing members are unavailable.
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
ensures that the operation does not block
indefinitely and instead ensures that the operation returns
an error if the read concern cannot be fulfilled.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
reference page.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A query with read concern
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
returns majority-committed data as it
appears across shards from a specific single point in time in the recent past.
Read concern
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
provides its guarantees only if the transaction
commits with write concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
.
</a>
</p>
<div class="line-block">
<div class="line">
If a transaction is not part of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions">
causally consistent
session
</a>
, upon transaction commit with write
concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
, the transaction operations
are guaranteed to have read from a snapshot of
majority-committed data.
</div>
</div>
<div class="line-block">
<div class="line">
If a transaction is part of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions">
causally consistent
session
</a>
, upon transaction commit with write
concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
, the transaction operations
are guaranteed to have read from a snapshot of
majority-committed data that provides causal consistency with
the operation immediately preceding the transaction start.
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<strong>
Availability:
</strong>
</p>
<p class="leafygreen-ui-1kp3ins">
Read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
is available for
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
All read operations inside multi-document transactions with the
read concern set at the transaction level.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The following methods outside of multi-document
transactions:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find">
<code class="leafygreen-ui-1l06pbn">
find
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate">
<code class="leafygreen-ui-1l06pbn">
aggregate
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/distinct/#mongodb-dbcommand-dbcmd.distinct">
<code class="leafygreen-ui-1l06pbn">
distinct
</code>
</a>
(on unsharded collections)
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
All other read operations prohibit
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
.
</a>
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
Regardless of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-read-concern">
read concern
</a>
level, the most recent data on a
node may not reflect the most recent version of the data in the system.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on each read concern level, see:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/">
Read Concern
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/">
Read Concern
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/">
Read Concern
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/">
Read Concern
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/">
Read Concern
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-defaults/">
Default MongoDB Read Concerns/Write Concerns
</a>
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
<code class="leafygreen-ui-1l06pbn">
readConcern
</code>
Support
<a class="headerlink leafygreen-ui-1kepx47" href="#readconcern-support" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="readconcern-support">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-read-concern-option">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Read Concern Option
<a class="headerlink leafygreen-ui-1kepx47" href="#read-concern-option" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-concern-option">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For operations not in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
multi-document transactions
</a>
, you can specify a
<code class="leafygreen-ui-1l06pbn">
readConcern
</code>
level as an
option to commands and methods that support read concern:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"readConcern: { level: <level> }","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">readConcern</span>: <!-- -->{ <span class="lg-highlight-attr">level</span>: <<!-- -->level<!-- -->> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To specify the read concern level for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
method
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
db.collection.find()
</code>
</a>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.readConcern/#mongodb-method-cursor.readConcern">
<code class="leafygreen-ui-1l06pbn">
cursor.readConcern()
</code>
</a>
method:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find().readConcern(<level>)","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">readConcern</span>(<<!-- -->level<!-- -->><!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Transactions and Available Read Concerns
<a class="headerlink leafygreen-ui-1kepx47" href="#transactions-and-available-read-concerns" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="transactions-and-available-read-concerns">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
multi-document transactions
</a>
, you set
the read concern at the transaction level, not at the individual
operation level. The operations in the transaction will use the
transaction-level read concern. Any read concern set at the collection
and database level is ignored inside the transaction. If the
transaction-level read concern is explicitly specified, the client
level read concern is also ignored inside the transaction.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Do not explicitly set the read concern for the individual
operations. To set the read concern for transactions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transaction-options">
Read Concern/Write Concern/Read Preference
<!-- -->
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can set the read concern at the transaction start:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For multi-document transaction, the following read concern levels are
available:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Write commands that are part of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
multi-document transactions
</a>
can support the transaction-level read concern.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-create-collections-indexes">
create collections and indexes
</a>
inside a transaction. If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-operations/#std-label-transactions-operations-ddl-explicit">
explicitly
</a>
creating a
collection or an index, the transaction must use read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
. If you
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-operations/#std-label-transactions-operations-ddl-implicit">
implicitly
</a>
create a collection, you can
use any of the read concerns available for transactions.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If unspecified at the transaction start, transactions use the
session-level read concern or, if that is unset, the client-level read
concern.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-read-concern">
Transaction Read Concern
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Causally Consistent Sessions and Available Read Concerns
<a class="headerlink leafygreen-ui-1kepx47" href="#causally-consistent-sessions-and-available-read-concerns" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="causally-consistent-sessions-and-available-read-concerns">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For operations in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency">
causally consistent session
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
levels are
available. However, to guarantee causal consistency, you must use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
. For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency">
Causal Consistency
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-read-concern-operations">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Operations That Support Read Concern
<a class="headerlink leafygreen-ui-1kepx47" href="#operations-that-support-read-concern" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="operations-that-support-read-concern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following operations support read concern:
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To set read concern for operations in a transaction, you set the
read concern at the transaction level, not at the individual
operation level. Do not explicitly set the read concern for the
individual operations in a transaction. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-read-concern">
Transactions and Read Concern
<!-- -->
.
</a>
</p>
</div>
</div>
<div class="header-buffer" id="ref-snapshot-id1">
</div>
<div class="header-buffer" id="ref-distinct-id2">
</div>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:35%"/>
<col style="width:5%"/>
<col style="width:10%"/>
<col style="width:10%"/>
<col style="width:20%"/>
<col style="width:20%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Command/Method
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
<a class="footnote-reference header-buffer" href="#footnote-snapshot" id="ref-snapshot-id1">
[
<!-- -->
3
<!-- -->
]
</a>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/count/#mongodb-dbcommand-dbcmd.count">
<code class="leafygreen-ui-1l06pbn">
count
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/distinct/#mongodb-dbcommand-dbcmd.distinct">
<code class="leafygreen-ui-1l06pbn">
distinct
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
<!-- -->
<a class="footnote-reference header-buffer" href="#footnote-distinct" id="ref-distinct-id2">
[
<!-- -->
2
<!-- -->
]
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/find/#mongodb-dbcommand-dbcmd.find">
<code class="leafygreen-ui-1l06pbn">
find
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
db.collection.find()
</code>
</a>
via
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.readConcern/#mongodb-method-cursor.readConcern">
<code class="leafygreen-ui-1l06pbn">
cursor.readConcern()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore">
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate">
<code class="leafygreen-ui-1l06pbn">
aggregate
</code>
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
db.collection.aggregate()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
<!-- -->
<a class="footnote-reference header-buffer" href="#footnote-3" id="ref-id3">
[
<!-- -->
3
<!-- -->
]
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Session.startTransaction/#mongodb-method-Session.startTransaction">
<code class="leafygreen-ui-1l06pbn">
Session.startTransaction()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-1" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<a href="#ref-id1">
1
</a>
]
</td>
<td class="leafygreen-ui-17r2xs0">
<!-- -->
You cannot use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
stage
in conjunction with read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
. That
is, if you specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
read concern for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
db.collection.aggregate()
</code>
</a>
, you cannot include either
stages in the pipeline.
</td>
</tr>
</tbody>
</table>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-distinct" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<a href="#ref-distinct-id2">
2
</a>
]
</td>
<td class="leafygreen-ui-17r2xs0">
<!-- -->
Read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
is available only for
certain read operations and for multi-document transactions. In a
transaction, you cannot use the
<code class="leafygreen-ui-1l06pbn">
distinct
</code>
command or its helpers
on a sharded collection.
</td>
</tr>
</tbody>
</table>
<p class="leafygreen-ui-1kp3ins">
The following write operations can also accept a read concern if part
of a multi-document transaction:
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To set read concern for operations in a transaction, you set the
read concern at the transaction level, not at the individual
operation level.
</p>
</div>
</div>
<div class="header-buffer" id="ref-snapshot-id4">
</div>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:35%"/>
<col style="width:5%"/>
<col style="width:10%"/>
<col style="width:10%"/>
<col style="width:20%"/>
<col style="width:20%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Command
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
"available"
</code>
</a>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
<a class="footnote-reference header-buffer" href="#footnote-snapshot" id="ref-snapshot-id4">
[
<!-- -->
3
<!-- -->
]
</a>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/delete/#mongodb-dbcommand-dbcmd.delete">
<code class="leafygreen-ui-1l06pbn">
delete
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.deleteOne/#mongodb-method-db.collection.deleteOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.deleteOne()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.deleteMany/#mongodb-method-db.collection.deleteMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.deleteMany()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.remove/#mongodb-method-db.collection.remove">
<code class="leafygreen-ui-1l06pbn">
db.collection.remove()
</code>
</a>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify">
<code class="leafygreen-ui-1l06pbn">
findAndModify
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#mongodb-method-db.collection.findAndModify">
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndDelete/#mongodb-method-db.collection.findOneAndDelete">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndDelete()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndReplace/#mongodb-method-db.collection.findOneAndReplace">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndReplace()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndUpdate()
</code>
</a>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/insert/#mongodb-dbcommand-dbcmd.insert">
<code class="leafygreen-ui-1l06pbn">
insert
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertOne/#mongodb-method-db.collection.insertOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.insertOne()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertMany/#mongodb-method-db.collection.insertMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.insertMany()
</code>
</a>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update">
<code class="leafygreen-ui-1l06pbn">
update
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateOne()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#mongodb-method-db.collection.updateMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateMany()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.replaceOne/#mongodb-method-db.collection.replaceOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.replaceOne()
</code>
</a>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/create/#mongodb-dbcommand-dbcmd.create">
<code class="leafygreen-ui-1l06pbn">
create
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createCollection/#mongodb-method-db.createCollection">
<code class="leafygreen-ui-1l06pbn">
db.createCollection()
</code>
</a>
</div>
<div class="line">
(Requires
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
fCV
</a>
4.4 or greater)
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/createIndexes/#mongodb-dbcommand-dbcmd.createIndexes">
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndex()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndexes/#mongodb-method-db.collection.createIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndexes()
</code>
</a>
</div>
<div class="line">
(Requires
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
fCV
</a>
4.4 or greater)
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
✓
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-snapshot" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<!-- -->
3
<!-- -->
]
</td>
<td class="leafygreen-ui-17r2xs0">
<em>
(
<a href="#ref-snapshot-id1">
1
</a>
,
<a href="#ref-snapshot-id4">
2
</a>
)
</em>
<!-- -->
Read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
is available only for
certain read operations and multi-document transactions. For transactions, you
set the read concern at the transaction level. The transaction
operations that support
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#mongodb-readconcern-readconcern.-snapshot-">
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
</a>
correspond to the
CRUD operations available in transactions. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-read-concern">
Transactions and Read Concern
<!-- -->
.
</a>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Read Concern not Supported on
<code class="leafygreen-ui-1l06pbn">
local
</code>
Database
<a class="headerlink leafygreen-ui-1kepx47" href="#read-concern-not-supported-on-local-database" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-concern-not-supported-on-local-database">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/local-database/#std-label-replica-set-local-database">
local database
</a>
does not support
read concerns. MongoDB silently ignores any configured read
concern for an operation on a collection in the local database.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#considerations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="considerations">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Read Your Own Writes
<a class="headerlink leafygreen-ui-1kepx47" href="#read-your-own-writes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-your-own-writes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions">
causally consistent sessions
</a>
to read your own
writes, if the writes request acknowledgment.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Real Time Order
<a class="headerlink leafygreen-ui-1kepx47" href="#real-time-order" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="real-time-order">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Combined with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
write concern,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
read concern enables multiple threads to
perform reads and writes on a single document as if a single thread
performed these operations in real time; that is, the corresponding
schedule for these reads and writes is considered linearizable.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Performance Comparisons
<a class="headerlink leafygreen-ui-1kepx47" href="#performance-comparisons" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="performance-comparisons">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Unlike
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
read
concern confirms with secondary members that the read operation is
reading from a primary that is capable of confirming writes with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
{ w: "majority" }
</code>
</a>
write concern.
<a class="footnote-reference header-buffer" href="#footnote-edge-cases-2-primaries" id="ref-edge-cases-2-primaries-id5">
[
<!-- -->
4
<!-- -->
]
</a>
As such, reads with linearizable read
concern may be significantly slower than reads with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-local/#mongodb-readconcern-readconcern.-local-">
<code class="leafygreen-ui-1l06pbn">
"local"
</code>
</a>
read concerns.
</p>
<p class="leafygreen-ui-1kp3ins">
Always use
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
with linearizable read concern in case a
majority of data bearing members are unavailable.
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
ensures
that the operation does not block indefinitely and instead ensures that
the operation returns an error if the read concern cannot be fulfilled.
</p>
<p class="leafygreen-ui-1kp3ins">
For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.restaurants.find( { _id: 5 } ).readConcern(\"linearizable\").maxTimeMS(10000)\n\ndb.runCommand( {\n find: \"restaurants\",\n filter: { _id: 5 },\n readConcern: { level: \"linearizable\" },\n maxTimeMS: 10000\n} )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">restaurants</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span> } ).<span class="lg-highlight-title lg-highlight-function">readConcern</span>(<span class="lg-highlight-string">"linearizable"</span>).<span class="lg-highlight-title lg-highlight-function">maxTimeMS</span>(<span class="lg-highlight-number">10000</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">find</span>: <span class="lg-highlight-string">"restaurants"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">filter</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">5</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">readConcern</span>: <!-- -->{ <span class="lg-highlight-attr">level</span>: <span class="lg-highlight-string">"linearizable"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">maxTimeMS</span>: <span class="lg-highlight-number">10000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-edge-cases-2-primaries" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<a href="#ref-edge-cases-2-primaries-id5">
4
</a>
]
</td>
<td class="leafygreen-ui-17r2xs0">
<!-- -->
In
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-use-cases/#std-label-edge-cases">
some circumstances
</a>
, two nodes in a replica set
may
<em>
transiently
</em>
believe that they are the primary, but at most, one
of them will be able to complete writes with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
{ w:
"majority" }
</code>
</a>
write concern. The node that can complete
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
{ w: "majority" }
</code>
</a>
writes is the current
primary, and the other node is a former primary that has not yet
recognized its demotion, typically due to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-network-partition">
network partition
</a>
.
When this occurs, clients that connect to the former primary may
observe stale data despite having requested read preference
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primary">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</a>
, and new writes to the former primary will
eventually roll back.
</td>
</tr>
</tbody>
</table>
<span class="leafygreen-ui-1qnjd6d" id="std-label-afterClusterTime">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Read Operations and
<code class="leafygreen-ui-1l06pbn">
afterClusterTime
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#read-operations-and-afterclustertime" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-operations-and-afterclustertime">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB includes support for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions">
causally consistent sessions
</a>
. For read operations associated with causally consistent
session, MongoDB supports the
<code class="leafygreen-ui-1l06pbn">
afterClusterTime
</code>
read concern
option to be set automatically by the drivers for operations associated
with causally consistent sessions.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Do not manually set
<code class="leafygreen-ui-1l06pbn">
afterClusterTime
</code>
for a read operation.
MongoDB drivers set this value automatically for operations
associated with causally consistent sessions. However, you can
advance the operation time and the cluster time for the session,
such as to be consistent with the operations of another client
session. For an example, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-causal-consistency-examples">
Examples
<!-- -->
.
</a>
</p>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
It is not possible to specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#std-label-atClusterTime">
atClusterTime
</a>
in
conjunction with
<code class="leafygreen-ui-1l06pbn">
afterClusterTime
</code>
. To use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-snapshot/#std-label-atClusterTime">
atClusterTime
</a>
with read concern
<code class="leafygreen-ui-1l06pbn">
"snapshot"
</code>
you have to disable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-isolation-consistency-recency/#std-label-sessions">
causally consistent sessions
<!-- -->
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To satisfy a read request with an
<code class="leafygreen-ui-1l06pbn">
afterClusterTime
</code>
value of
<code class="leafygreen-ui-1l06pbn">
T
</code>
,
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
must perform the request after its oplog
reaches time
<code class="leafygreen-ui-1l06pbn">
T
</code>
. If its oplog has not reached time
<code class="leafygreen-ui-1l06pbn">
T
</code>
, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
must wait to service the request.
</p>
<p class="leafygreen-ui-1kp3ins">
Read operations with a specified
<code class="leafygreen-ui-1l06pbn">
afterClusterTime
</code>
return data that
meet both the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-read-concern-levels" target="_self">
<span>
read concern level
</span>
</a>
requirement and the specified
<code class="leafygreen-ui-1l06pbn">
afterClusterTime
</code>
requirement.
</p>
<p class="leafygreen-ui-1kp3ins">
For read operations not associated with causally consistent sessions,
<code class="leafygreen-ui-1l06pbn">
afterClusterTime
</code>
is unset.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Read Concern Provenance
<a class="headerlink leafygreen-ui-1kepx47" href="#read-concern-provenance" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="read-concern-provenance">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB tracks read concern
<code class="leafygreen-ui-1l06pbn">
provenance
</code>
, which indicates the source of a
particular read concern. You may see
<code class="leafygreen-ui-1l06pbn">
provenance
</code>
shown in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.metrics.getLastError">
<code class="leafygreen-ui-1l06pbn">
getLastError
</code>
</a>
metrics, read
concern error objects, and MongoDB logs.
</p>
<p class="leafygreen-ui-1kp3ins">
The following table shows the possible read concern
<code class="leafygreen-ui-1l06pbn">
provenance
</code>
values and their significance:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:40%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Provenance
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
clientSupplied
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The read concern was specified in the application.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
customDefault
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The read concern originated from a custom defined
default value. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#mongodb-dbcommand-dbcmd.setDefaultRWConcern">
<code class="leafygreen-ui-1l06pbn">
setDefaultRWConcern
</code>
.
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
implicitDefault
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The read concern originated from the server in absence
of all other read concern specifications.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/release-notes/5.0-downgrade-standalone/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Downgrade
<!-- -->
5.0
<!-- -->
Standalone to
<!-- -->
4.4
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-newversion-standalone-to-oldversion" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="downgrade-newversion-standalone-to-oldversion">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#downgrade-path" target="_self">
<span>
Downgrade Path
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#create-backup" target="_self">
<span>
Create Backup
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#access-control" target="_self">
<span>
Access Control
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#prerequisites" target="_self">
<span>
Prerequisites
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#procedure" target="_self">
<span>
Procedure
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Before you attempt any downgrade, familiarize yourself with the content
of this document.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Downgrade Path
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-path" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="downgrade-path">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If you need to downgrade from
<!-- -->
5.0
<!-- -->
, downgrade to the latest
patch release of
<!-- -->
4.4
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB only supports single-version downgrades. You cannot downgrade to a
release that is multiple versions behind your current release.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, you may downgrade a
<!-- -->
5.0-series
<!-- -->
to a
<!-- -->
4.4-series
<!-- -->
deployment.
However, further downgrading that
<!-- -->
4.4-series
<!-- -->
deployment to a
<!-- -->
4.2-series
<!-- -->
deployment is not supported.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Create Backup
<a class="headerlink leafygreen-ui-1kepx47" href="#create-backup" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="create-backup">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional but Recommended.
</em>
Create a backup of your database.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Access Control
<a class="headerlink leafygreen-ui-1kepx47" href="#access-control" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="access-control">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If your deployment has access control enabled, your downgrade user
privileges must include privileges to list and manage indexes across
databases. A user with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-root">
<code class="leafygreen-ui-1l06pbn">
root
</code>
</a>
role has the required privileges.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Prerequisites
<a class="headerlink leafygreen-ui-1kepx47" href="#prerequisites" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="prerequisites">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To downgrade from
<!-- -->
5.0
<!-- -->
to
<!-- -->
4.4
<!-- -->
, you must remove
incompatible features that are persisted and/or update incompatible
configuration settings. These include:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
1. Cluster Default Read and Write Concerns
<a class="headerlink leafygreen-ui-1kepx47" href="#1.-cluster-default-read-and-write-concerns" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="1.-cluster-default-read-and-write-concerns">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 5.0 changed the default value for cluster-wide read and write
concerns, and downgrading to MongoDB 4.4 might change those defaults
back. Consider manually configuring your cluster's default read and
write concern before downgrading:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To manually configure a default value for a cluster's read or write
concern, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#mongodb-dbcommand-dbcmd.setDefaultRWConcern">
<code class="leafygreen-ui-1l06pbn">
setDefaultRWConcern
</code>
</a>
command.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If your cluster includes an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-arbiter/">
arbiter
</a>
, and you had previously disabled
<code class="leafygreen-ui-1l06pbn">
"Majority"
</code>
read concern to prevent cache pressure in certain
situations, you may want to configure
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--enableMajorityReadConcern">
<code class="leafygreen-ui-1l06pbn">
--enableMajorityReadConcern false
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.enableMajorityReadConcern">
<code class="leafygreen-ui-1l06pbn">
replication.enableMajorityReadConcern: false
</code>
</a>
once you downgrade.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
2. Document Fields with
<code class="leafygreen-ui-1l06pbn">
.
</code>
or
<code class="leafygreen-ui-1l06pbn">
$
</code>
Characters
<a class="headerlink leafygreen-ui-1kepx47" href="#2.-document-fields-with-.-or---characters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="2.-document-fields-with-.-or---characters">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 5.0 adds support for including the
<code class="leafygreen-ui-1l06pbn">
.
</code>
or
<code class="leafygreen-ui-1l06pbn">
$
</code>
characters in
document field names. You must delete any documents containing field
names that include the
<code class="leafygreen-ui-1l06pbn">
.
</code>
or
<code class="leafygreen-ui-1l06pbn">
$
</code>
characters before downgrading
to MongoDB 4.4.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
3. Slim-format Timezone Data Files
<a class="headerlink leafygreen-ui-1kepx47" href="#3.-slim-format-timezone-data-files" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="3.-slim-format-timezone-data-files">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 5.0 enables support for slim-format timezone data files. If
using slim-format timezone data files in your deployment, as provided
to MongoDB with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--timeZoneInfo">
<code class="leafygreen-ui-1l06pbn">
--timeZoneInfo
</code>
</a>
command line option or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-processManagement.timeZoneInfo">
<code class="leafygreen-ui-1l06pbn">
processManagement.timeZoneInfo
</code>
</a>
configuration file setting, you must downgrade to MongoDB 4.4.7 or
later, or else revert your timezone data files to use the previous
non-slim-format data files.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-5.0-downgrade-feature-compatibility-standalone">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
4. Downgrade Feature Compatibility Version (fCV)
<a class="headerlink leafygreen-ui-1kepx47" href="#4.-downgrade-feature-compatibility-version--fcv-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="4.-downgrade-feature-compatibility-version--fcv-">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To downgrade the
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
of your standalone:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Connect a
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance
<!-- -->
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Downgrade the
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
to
<code class="leafygreen-ui-1l06pbn">
"4.4"
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand({setFeatureCompatibilityVersion: \"4.4\"})","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-1b1bvay">
<pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(<!-- -->{<span class="lg-highlight-attr">setFeatureCompatibilityVersion</span>: <span class="lg-highlight-string">"4.4"</span>})</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
command performs writes
to an internal system collection and is idempotent. If for any reason
the command does not complete successfully, retry the command on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance
<!-- -->
.
</p>
</li>
</ol>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
5. Remove fCV
<!-- -->
5.0
<!-- -->
Persisted Features
<a class="headerlink leafygreen-ui-1kepx47" href="#5.-remove-fcv-newversion-persisted-features" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="5.-remove-fcv-newversion-persisted-features">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following steps are necessary only if fCV has ever been set to
<code class="leafygreen-ui-1l06pbn">
"5.0"
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Remove all persisted
<!-- -->
5.0
<!-- -->
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0-compatibility/#std-label-5.0-compatibility-enabled">
features
</a>
that are incompatible with
<!-- -->
4.4
<!-- -->
. These include:
</p>
<dl>
<dt>
Time-series Collections
</dt>
<dd class="css-1ufxuu7">
Remove all
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
time series collections
<!-- -->
.
</a>
</dd>
<dt>
Runtime Audit Filter Management
</dt>
<dd class="css-1ufxuu7">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Disable Runtime Audit Filter Management by setting
<code class="leafygreen-ui-1l06pbn">
auditLog.runtimeConfiguration
</code>
to
<code class="leafygreen-ui-1l06pbn">
false
</code>
in the node's
configuration file.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Update the audit filters for this instance in the local
configuration file.
</p>
</li>
</ul>
</dd>
</dl>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
6. Remove
<!-- -->
5.0
<!-- -->
Features
<a class="headerlink leafygreen-ui-1kepx47" href="#6.-remove-newversion-features" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="6.-remove-newversion-features">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Remove all persisted features that use
<!-- -->
5.0
<!-- -->
features. These
include but are not limited to:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If any view definitions include 5.0 operators, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateAdd/#mongodb-expression-exp.-dateAdd">
<code class="leafygreen-ui-1l06pbn">
$dateAdd
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sampleRate/#mongodb-expression-exp.-sampleRate">
<code class="leafygreen-ui-1l06pbn">
$sampleRate
</code>
</a>
, they must be
removed. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0/#std-label-5.0-rel-notes-new-agg-operators">
New Aggregation Operators
</a>
for the full list.
</p>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Procedure
<a class="headerlink leafygreen-ui-1kepx47" href="#procedure" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="procedure">
</div>
</a>
</h2>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Before proceeding with the downgrade procedure, ensure that the
prerequisites have been completed.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Download the latest 4.4 binaries.Using either a package manager or a manual download, get the latest\nrelease in the 4.4 series. If using a package manager, add a new\nrepository for the 4.4 binaries, then perform the actual downgrade\nprocess.Before you upgrade or downgrade a replica set, ensure all replica set\nmembers are running. If you do not, the upgrade or downgrade will not\ncomplete until all members are started.If you need to downgrade from 5.0, downgrade to the latest\npatch release of 4.4."},{"@type":"HowToStep","text":"Shut down the mongod instance.To cleanly shut down the mongod process, connect\nmongosh to the instance and run:A clean shutdown of a\nmongod completes all pending operations,\nflushes all data to data files, and closes all data files."},{"@type":"HowToStep","text":"Update configuration files.Disable any configurable 5.0 features by updating the\nmongod instance's configuration file before\nrestarting."},{"@type":"HowToStep","text":"Restart with the latest 4.4 mongod instance.Replace the 5.0 binary with the downloaded 4.4\nmongod binary and restart."}],"name":"Procedure","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
</script>
<div class="css-4nyere eccljxs0">
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
1
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Download the latest
<!-- -->
4.4
<!-- -->
binaries.
<a class="headerlink leafygreen-ui-1kepx47" href="#download-the-latest-binaries" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="download-the-latest-binaries">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Using either a package manager or a manual download, get the latest
release in the
<!-- -->
4.4
<!-- -->
series. If using a package manager, add a new
repository for the
<!-- -->
4.4
<!-- -->
binaries, then perform the actual downgrade
process.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Before you upgrade or downgrade a replica set, ensure all replica set
members are running. If you do not, the upgrade or downgrade will not
complete until all members are started.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you need to downgrade from
<!-- -->
5.0
<!-- -->
, downgrade to the latest
patch release of
<!-- -->
4.4
<!-- -->
.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
2
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Shut down the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
instance.
<a class="headerlink leafygreen-ui-1kepx47" href="#shut-down-the-mongod-instance" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="shut-down-the-mongod-instance">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To cleanly shut down the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process, connect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
to the instance and run:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { shutdown: 1 } )","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-yzcs8i">
<pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">shutdown</span>: <span class="lg-highlight-number">1</span> } )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-mongodb-processes/#std-label-terminate-mongod-processes">
clean shutdown
</a>
of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
completes all pending operations,
flushes all data to data files, and closes all data files.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
3
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update configuration files.
<a class="headerlink leafygreen-ui-1kepx47" href="#update-configuration-files" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="update-configuration-files">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Disable any configurable
<!-- -->
5.0
<!-- -->
features by updating the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance's configuration file before
restarting.
</p>
</section>
</div>
</div>
<div class="css-1nuklj8 e1ckbxcu1">
<div class="css-18fui5z e1ckbxcu0">
<div class="css-19lsqsq e1ckbxcu2">
4
</div>
</div>
<div class="css-1ed38mk">
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Restart with the latest
<!-- -->
4.4
<!-- -->
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
instance.
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-with-the-latest-mongod-instance" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="restart-with-the-latest-mongod-instance">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Replace the
<!-- -->
5.0
<!-- -->
binary with the downloaded
<!-- -->
4.4
<!-- -->
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
binary and restart.
</p>
</section>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/csfle/reference/csfle-options-clients/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
MongoClient Options for CSFLE
<a class="headerlink leafygreen-ui-1kepx47" href="#mongoclient-options-for-csfle" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongoclient-options-for-csfle">
</div>
</a>
</h1>
<div class="leafygreen-ui-a5yxub">
<p class="css-1cmx2d4 ef7gu8j0">
On this page
</p>
<ul class="css-1qb0mst ef7gu8j1">
<li class="leafygreen-ui-1e7a0ei">
<a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#overview" target="_self">
<span>
Overview
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#autoencryptionopts" target="_self">
<span>
AutoEncryptionOpts
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
<span>
Example
</span>
</a>
</li>
</ul>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Overview
<a class="headerlink leafygreen-ui-1kepx47" href="#overview" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="overview">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
View information about the Client-Side Field Level Encryption (CSFLE)-specific
configuration options for
<code class="leafygreen-ui-1l06pbn">
MongoClient
</code>
instances.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
AutoEncryptionOpts
<a class="headerlink leafygreen-ui-1kepx47" href="#autoencryptionopts" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="autoencryptionopts">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Pass an
<code class="leafygreen-ui-1l06pbn">
autoEncryptionOpts
</code>
object to your
<code class="leafygreen-ui-1l06pbn">
MongoClient
</code>
instance to specify CSFLE-specific options.
</p>
<p class="leafygreen-ui-1kp3ins">
The following table describes the structure of an
<code class="leafygreen-ui-1l06pbn">
autoEncryptionOpts
</code>
object:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:10%"/>
<col style="width:10%"/>
<col style="width:60%"/>
</colgroup>
<thead class="leafygreen-ui-a9ho40">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Parameter
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Required
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Description
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
keyVaultClient
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
MongoClient
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
No
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A
<code class="leafygreen-ui-1l06pbn">
MongoClient
</code>
instance configured to connect to
the MongoDB instance hosting your Key Vault collection.
</p>
<p class="leafygreen-ui-1kp3ins">
If you omit the
<code class="leafygreen-ui-1l06pbn">
keyVaultClient
</code>
option, the MongoDB instance specified
to your
<code class="leafygreen-ui-1l06pbn">
MongoClient
</code>
instance containing the
<code class="leafygreen-ui-1l06pbn">
autoEncryptionOpts
</code>
configuration is used as the
host of your Key Vault collection.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about Key Vault collections, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults">
Encryption Keys and Key Vaults
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
keyVaultNamespace
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
String
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Yes
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The full
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
namespace
</a>
of the Key Vault collection.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
kmsProviders
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Object
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Yes
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The Key Management System (KMS) used by Client-Side Field Level Encryption for
managing your Customer Master Keys (CMKs).
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about
<code class="leafygreen-ui-1l06pbn">
kmsProviders
</code>
objects, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers">
KMS Providers
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about Customer Master Keys, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/#std-label-qe-reference-keys-key-vaults">
Encryption Keys and Key Vaults
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
tlsOptions
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Object
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
No
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
An object that maps Key Management System provider names to TLS configuration
options.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about TLS options see:
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-label-tls-mongod-options">
TLS Options
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about TLS see:
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-transport-encryption/#std-label-transport-encryption">
TLS/SSL (Transport Encryption)
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
schemaMap
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Object
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
No
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
An encryption schema.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn how to construct an encryption schema, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/create-schema/#std-label-csfle-fundamentals-create-schema">
Encryption Schemas
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For complete documentation of encryption schemas, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/encryption-schemas/#std-label-csfle-reference-encryption-schemas">
CSFLE Encryption Schemas
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bypassAutoEncryption
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
No
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specify
<code class="leafygreen-ui-1l06pbn">
true
</code>
to bypass automatic Client-Side Field Level Encryption rules
and perform explicit encryption.
<code class="leafygreen-ui-1l06pbn">
bypassAutoEncryption
</code>
does not
disable automatic decryption.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about this option, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/manual-encryption/#std-label-csfle-fundamentals-manual-encryption-automatic-decryption">
Automatic Decryption
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-csfle-enc-options-example">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Example
<a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="example">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To view a code-snippet demonstrating how to use
<code class="leafygreen-ui-1l06pbn">
autoEncryptionOpts
</code>
to configure your
<code class="leafygreen-ui-1l06pbn">
MongoClient
</code>
instance, select the tab corresponding to your driver:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-7">
<div aria-label="Tabs to describe usage of drivers" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_9fuh5pb38" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_vqcwwqhkt" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
MongoDB Shell
</div>
</button>
<button aria-controls="_7arfivqdn" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_yatlxoxvc" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
C#
</div>
</button>
<button aria-controls="_sh70p9zo6" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_kpbydgyrz" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Go
</div>
</button>
<button aria-controls="_rrvglat17" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_4dmupw4rr" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Java (Sync)
</div>
</button>
<button aria-controls="_12nf3pxg1" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_21slywwjl" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Node.js
</div>
</button>
<button aria-controls="_eyznsezeq" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_lng08qor2" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Python
</div>
</button>
</div>
<div class="leafygreen-ui-ov1ktg">
<div class="leafygreen-ui-1sg2lsz">
</div>
</div>
</div>
<div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
<div>
<div aria-labelledby="_umq240vzq" class="leafygreen-ui-38lglc" id="_1nkt7jbvu" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var autoEncryptionOpts =\n{\n \"keyVaultNamespace\" : \"<database>.<collection>\",\n \"kmsProviders\" : { ... },\n \"schemaMap\" : { ... }\n}\n\ncluster = Mongo(\n \"<your>\",\n autoEncryptionOpts\n);\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> autoEncryptionOpts <!-- -->=</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"keyVaultNamespace"</span> <!-- -->: <span class="lg-highlight-string">"<database>.<collection>"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"kmsProviders"</span> <!-- -->: <!-- -->{ <!-- -->...<!-- --> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"schemaMap"</span> <!-- -->: <!-- -->{ <!-- -->...<!-- --> }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">}</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">cluster <!-- -->= <span class="lg-highlight-title lg-highlight-class">Mongo</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<Your Connection String>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->autoEncryptionOpts</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-16-menu" aria-describedby="select-16-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-17" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rs:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rs:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rs:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rs:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Environment Variables
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
If possible, consider defining the credentials provided in
<code class="leafygreen-ui-1l06pbn">
kmsProviders
</code>
as environment variables, and then passing them
to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/options/#std-option-mongosh.--eval" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
--eval
</code>
</span>
</a>
option. This minimizes the chances of credentials
leaking into logs.
</p>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_lgwmptzuo" class="leafygreen-ui-38lglc" id="_us2acewbq" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var clientSettings = MongoClientSettings.FromConnectionString(_connectionString);\nvar autoEncryptionOptions = new AutoEncryptionOptions(\n keyVaultNamespace: keyVaultNamespace,\n kmsProviders: kmsProviders,\n schemaMap: schemaMap,\n extraOptions: extraOptions);\nclientSettings.AutoEncryptionOptions = autoEncryptionOptions;\nvar client = new MongoClient(clientSettings);\n","programmingLanguage":"C#"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-class">FromConnectionString</span>(_connectionString);</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> autoEncryptionOptions = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOptions</span>(</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNamespace</span>: keyVaultNamespace,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: kmsProviders,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaMap</span>: schemaMap,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: extraOptions);</td></tr><tr class=""><td class="leafygreen-ui-7razhx">clientSettings.<span class="lg-highlight-property">AutoEncryptionOptions</span> = autoEncryptionOptions;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">var</span> client = <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(clientSettings);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-19-menu" aria-describedby="select-19-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-20" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rt:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rt:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rt:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rt:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_o0kv5xgzf" class="leafygreen-ui-38lglc" id="_g34kur2hg" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"autoEncryptionOpts := options.AutoEncryption().\n\tSetKmsProviders(provider.Credentials()).\n\tSetKeyVaultNamespace(keyVaultNamespace).\n\tSetSchemaMap(schemaMap).\n\tSetExtraOptions(extraOptions)\nclient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri).SetAutoEncryptionOptions(autoEncryptionOpts))\n\n","programmingLanguage":"Golang"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">autoEncryptionOpts <!-- -->:<!-- -->= options.<span class="lg-highlight-title lg-highlight-class">AutoEncryption</span>().</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKmsProviders</span>(provider.<span class="lg-highlight-title lg-highlight-class">Credentials</span>()).</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetKeyVaultNamespace</span>(keyVaultNamespace).</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetSchemaMap</span>(schemaMap).</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">SetExtraOptions</span>(extraOptions)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">client<!-- -->, <!-- -->err := mongo.<span class="lg-highlight-title lg-highlight-class">Connect</span>(context.<span class="lg-highlight-title lg-highlight-function">TODO</span>(), options.<span class="lg-highlight-title lg-highlight-class">Client</span>().<span class="lg-highlight-title lg-highlight-class">ApplyURI</span>(uri).<span class="lg-highlight-title lg-highlight-class">SetAutoEncryptionOptions</span>(autoEncryptionOpts))</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-22-menu" aria-describedby="select-22-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-23" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:ru:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":ru:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ru:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":ru:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_t75tb6wtm" class="leafygreen-ui-38lglc" id="_ai7geuyn6" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"MongoClientSettings clientSettings = MongoClientSettings.builder()\n .applyConnectionString(new ConnectionString(\"mongodb://localhost:27017\"))\n .autoEncryptionSettings(AutoEncryptionSettings.builder()\n .keyVaultNamespace(keyVaultNamespace)\n .kmsProviders(kmsProviders)\n .schemaMap(schemaMap)\n .extraOptions(extraOptions)\n .build())\n .build();\n\nMongoClient mongoClient = MongoClients.create(clientSettings);\n","programmingLanguage":"Java"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span> clientSettings = <span class="lg-highlight-title lg-highlight-class">MongoClientSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">applyConnectionString</span>(<span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">ConnectionString</span>(<span class="lg-highlight-string">"mongodb://localhost:27017"</span>))</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">autoEncryptionSettings</span>(<span class="lg-highlight-title lg-highlight-class">AutoEncryptionSettings</span>.<span class="lg-highlight-title lg-highlight-function">builder</span>()</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">keyVaultNamespace</span>(keyVaultNamespace)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">kmsProviders</span>(kmsProviders)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">schemaMap</span>(schemaMap)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">extraOptions</span>(extraOptions)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>())</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> .<span class="lg-highlight-title lg-highlight-function">build</span>();</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-title lg-highlight-class">MongoClient</span> mongoClient = <span class="lg-highlight-title lg-highlight-class">MongoClients</span>.<span class="lg-highlight-title lg-highlight-function">create</span>(clientSettings);</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-25-menu" aria-describedby="select-25-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-26" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:rv:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":rv:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rv:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":rv:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_z6hj6n4dp" class="" id="_g408o4npe" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const secureClient = new MongoClient(connectionString, {\n monitorCommands: true,\n autoEncryption: {\n keyVaultNamespace,\n kmsProviders,\n schemaMap: patientSchema,\n extraOptions: extraOptions,\n },\n});\n","programmingLanguage":"JavaScript"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> secureClient <!-- -->= <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(<!-- -->connectionString<!-- -->, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">monitorCommands</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">autoEncryption</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->keyVaultNamespace<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->kmsProviders<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schemaMap</span>: <!-- -->patientSchema<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: <!-- -->extraOptions<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">})<!-- -->;</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-28-menu" aria-describedby="select-28-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-29" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r10:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r10:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r10:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r10:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_93cis9irr" class="leafygreen-ui-38lglc" id="_t00pv677d" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"fle_opts = AutoEncryptionOpts(\n kms_providers,\n key_vault_namespace,\n schema_map=patient_schema,\n **extra_options\n)\nclient = MongoClient(connection_string, auto_encryption_opts=fle_opts)\n","programmingLanguage":"Python"}
</script>
<div class="css-16lmvu9">
<div class="leafygreen-ui-196mwvg">
<div class="leafygreen-ui-9lvdmr">
<pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">fle_opts = <span class="lg-highlight-title lg-highlight-class">AutoEncryptionOpts</span>(</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> kms_providers,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> key_vault_namespace,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> schema_map=patient_schema,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> **extra_options</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">client = <span class="lg-highlight-title lg-highlight-class">MongoClient</span>(connection_string, auto_encryption_opts=fle_opts)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-hcrzu6" data-testid="leafygreen-code-panel">
<div class="leafygreen-ui-148abs6">
<div class="leafygreen-ui-omjz13" data-lgid="lg-select">
<button aria-controls="select-31-menu" aria-describedby="select-31-description" aria-disabled="false" aria-expanded="false" aria-invalid="false" aria-labelledby="Language Picker" class="lg-ui-button-0000 leafygreen-ui-dvfj9v" data-lgid="lg-button" data-testid="leafygreen-ui-select-menubutton" id="select-32" type="button" value="Node.js">
<div class="leafygreen-ui-v038xi">
</div>
<div class="leafygreen-ui-16tr4y">
<svg aria-hidden="true" class="leafygreen-ui-18si895" fill="none" role="presentation" viewbox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_2131_12968)">
<mask height="19" id="mask0_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask0_2131_12968)">
<mask height="19" id="mask1_2131_12968" maskunits="userSpaceOnUse" width="30" x="0" y="6">
<path d="M30 6.04395H0V24.3825H30V6.04395Z" fill="white">
</path>
</mask>
<g mask="url(#mask1_2131_12968)">
<path d="M14.8241 24.3823C14.7224 24.3823 14.6274 24.3552 14.5393 24.3078L13.6374 23.7731C13.5018 23.6986 13.5696 23.6715 13.6103 23.658C13.7934 23.597 13.8273 23.5835 14.0172 23.4751C14.0375 23.4616 14.0646 23.4684 14.085 23.4819L14.7767 23.8949C14.8038 23.9084 14.8377 23.9084 14.858 23.8949L17.5637 22.3311C17.5909 22.3176 17.6044 22.2905 17.6044 22.2567V19.136C17.6044 19.1021 17.5909 19.075 17.5637 19.0615L14.858 17.5045C14.8309 17.4909 14.797 17.4909 14.7767 17.5045L12.071 19.0615C12.0439 19.075 12.0302 19.1089 12.0302 19.136V22.2567C12.0302 22.2838 12.0439 22.3176 12.071 22.3311L12.8101 22.7576C13.2102 22.9607 13.4611 22.7237 13.4611 22.4868V19.4067C13.4611 19.3661 13.495 19.3255 13.5425 19.3255H13.8884C13.929 19.3255 13.9697 19.3593 13.9697 19.4067V22.4868C13.9697 23.0217 13.6781 23.333 13.1695 23.333C13.0136 23.333 12.8915 23.333 12.5457 23.1638L11.8336 22.7576C11.6574 22.6561 11.5488 22.4665 11.5488 22.2635V19.1427C11.5488 18.9396 11.6574 18.7501 11.8336 18.6485L14.5393 17.0848C14.7089 16.99 14.9394 16.99 15.109 17.0848L17.8146 18.6485C17.9909 18.7501 18.0995 18.9396 18.0995 19.1427V22.2635C18.0995 22.4665 17.9909 22.6561 17.8146 22.7576L15.109 24.3214C15.0276 24.3552 14.9259 24.3823 14.8241 24.3823Z" fill="black">
</path>
<path d="M15.6643 22.2362C14.4775 22.2362 14.2334 21.6946 14.2334 21.2343C14.2334 21.1936 14.2673 21.153 14.3147 21.153H14.6674C14.7081 21.153 14.742 21.1801 14.742 21.2207C14.7963 21.5795 14.9522 21.7555 15.671 21.7555C16.2407 21.7555 16.4847 21.6269 16.4847 21.3223C16.4847 21.1462 16.4169 21.0177 15.5286 20.9297C14.7895 20.8552 14.3284 20.6928 14.3284 20.1038C14.3284 19.5555 14.7895 19.2305 15.5625 19.2305C16.4305 19.2305 16.8577 19.5284 16.912 20.1782C16.912 20.1986 16.9052 20.2189 16.8916 20.2392C16.8781 20.2527 16.8577 20.2663 16.8374 20.2663H16.4779C16.4441 20.2663 16.4101 20.2392 16.4034 20.2053C16.322 19.833 16.1118 19.7111 15.5557 19.7111C14.9319 19.7111 14.8573 19.9278 14.8573 20.0902C14.8573 20.2866 14.9454 20.3475 15.7863 20.4558C16.6204 20.5641 17.0137 20.7198 17.0137 21.302C17.0137 21.8977 16.5187 22.2362 15.6643 22.2362Z" fill="black">
</path>
<path d="M19.5706 18.9597C19.5706 19.244 19.3333 19.481 19.0485 19.481C18.7636 19.481 18.5264 19.2507 18.5264 18.9597C18.5264 18.6618 18.7704 18.4385 19.0485 18.4385C19.3265 18.4385 19.5706 18.6686 19.5706 18.9597ZM18.6077 18.9597C18.6077 19.2034 18.8044 19.3997 19.0417 19.3997C19.2859 19.3997 19.4825 19.1967 19.4825 18.9597C19.4825 18.716 19.2859 18.5264 19.0417 18.5264C18.8111 18.5264 18.6077 18.716 18.6077 18.9597ZM18.8519 18.6686H19.0553C19.1231 18.6686 19.2587 18.6686 19.2587 18.8243C19.2587 18.9326 19.1909 18.9529 19.1502 18.9664C19.2316 18.9732 19.2384 19.0274 19.2451 19.1019C19.2519 19.1493 19.2587 19.2304 19.2722 19.2575H19.1502C19.1502 19.2304 19.1298 19.0815 19.1298 19.0748C19.1231 19.0409 19.1095 19.0274 19.0688 19.0274H18.9672V19.2643H18.8519V18.6686ZM18.9603 18.9258H19.0485C19.1231 18.9258 19.1366 18.8716 19.1366 18.8446C19.1366 18.7634 19.0824 18.7634 19.0485 18.7634H18.9535V18.9258H18.9603Z" fill="black">
</path>
<path clip-rule="evenodd" d="M6.43536 12.1766C6.43536 12.0548 6.36754 11.9397 6.25904 11.8788L3.39059 10.2202C3.34313 10.1932 3.28887 10.1796 3.23463 10.1729C3.22785 10.1729 3.20751 10.1729 3.20751 10.1729C3.15325 10.1729 3.09901 10.1932 3.05154 10.2202L0.176311 11.872C0.067812 11.9329 0 12.048 0 12.1766L0.00678119 16.6174C0.00678119 16.6783 0.0406871 16.7393 0.0949364 16.7663C0.149187 16.8002 0.216998 16.8002 0.264466 16.7663L1.97332 15.7915C2.08183 15.7306 2.14964 15.6155 2.14964 15.4936V13.4154C2.14964 13.2936 2.21745 13.1785 2.32595 13.1176L3.05154 12.6979C3.10579 12.664 3.16682 12.6505 3.22785 12.6505C3.28887 12.6505 3.34991 12.664 3.39738 12.6979L4.12297 13.1176C4.23147 13.1785 4.29927 13.2936 4.29927 13.4154V15.4936C4.29927 15.6155 4.36709 15.7306 4.47559 15.7915L6.17089 16.7663C6.22513 16.8002 6.29295 16.8002 6.3472 16.7663C6.40144 16.7393 6.43536 16.6783 6.43536 16.6174V12.1766Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M20.2551 6.06425C20.201 6.03718 20.1332 6.03718 20.0857 6.06425C20.0314 6.0981 19.9975 6.15226 19.9975 6.21318V10.6133C19.9975 10.654 19.9771 10.6946 19.9364 10.7217C19.8958 10.742 19.8551 10.742 19.8144 10.7217L19.0956 10.3087C18.9871 10.2478 18.8582 10.2478 18.7498 10.3087L15.8746 11.9673C15.766 12.0282 15.6982 12.1433 15.6982 12.2651V15.5754C15.6982 15.6973 15.766 15.8123 15.8746 15.8732L18.7498 17.5318C18.8582 17.5927 18.9871 17.5927 19.0956 17.5318L21.9708 15.8732C22.0793 15.8123 22.1471 15.6973 22.1471 15.5754V7.32338C22.1471 7.19476 22.0793 7.07968 21.9708 7.01875L20.2551 6.06425ZM19.9907 14.4855C19.9907 14.5194 19.9771 14.5464 19.9501 14.56L18.9667 15.1286C18.9397 15.1421 18.9057 15.1421 18.8786 15.1286L17.8953 14.56C17.8682 14.5464 17.8547 14.5126 17.8547 14.4855V13.3482C17.8547 13.3144 17.8682 13.2873 17.8953 13.2738L18.8786 12.7051C18.9057 12.6916 18.9397 12.6916 18.9667 12.7051L19.9501 13.2738C19.9771 13.2873 19.9907 13.3212 19.9907 13.3482V14.4855Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M29.8235 13.3214C29.932 13.2605 29.9931 13.1454 29.9931 13.0235V12.218C29.9931 12.0961 29.9253 11.981 29.8235 11.9201L26.9687 10.2683C26.8602 10.2074 26.7314 10.2074 26.6228 10.2683L23.7476 11.9269C23.6391 11.9878 23.5713 12.1029 23.5713 12.2247V15.535C23.5713 15.6569 23.6391 15.772 23.7476 15.8328L26.6025 17.4575C26.7109 17.5185 26.8398 17.5185 26.9415 17.4575L28.6707 16.4963C28.725 16.4692 28.7589 16.4083 28.7589 16.3474C28.7589 16.2864 28.725 16.2255 28.6707 16.1984L25.782 14.5399C25.7277 14.506 25.6938 14.4519 25.6938 14.391V13.3552C25.6938 13.2943 25.7277 13.2334 25.782 13.2063L26.6839 12.6918C26.7381 12.658 26.8059 12.658 26.8602 12.6918L27.7621 13.2063C27.8163 13.2402 27.8502 13.2943 27.8502 13.3552V14.1676C27.8502 14.2285 27.8841 14.2894 27.9384 14.3165C27.9927 14.3504 28.0605 14.3504 28.1147 14.3165L29.8235 13.3214Z" fill="black" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M26.7521 13.1654C26.7724 13.1519 26.7996 13.1519 26.8199 13.1654L27.3692 13.4836C27.3895 13.4971 27.4031 13.5174 27.4031 13.5445V14.1809C27.4031 14.2079 27.3895 14.2282 27.3692 14.2418L26.8199 14.5599C26.7996 14.5735 26.7724 14.5735 26.7521 14.5599L26.2028 14.2418C26.1825 14.2282 26.1689 14.2079 26.1689 14.1809V13.5445C26.1689 13.5174 26.1825 13.4971 26.2028 13.4836L26.7521 13.1654Z" fill="#5FA04E" fill-rule="evenodd">
</path>
<path d="M11.2331 10.2292C11.1227 10.1671 10.9917 10.1671 10.8814 10.2292L7.97807 11.9053C7.86772 11.9673 7.80566 12.0846 7.80566 12.2088V15.5679C7.80566 15.692 7.87462 15.8092 7.97807 15.8714L10.8814 17.5474C10.9917 17.6095 11.1227 17.6095 11.2331 17.5474L14.1364 15.8714C14.2467 15.8092 14.3088 15.692 14.3088 15.5679V12.2088C14.3088 12.0846 14.2398 11.9673 14.1364 11.9053L11.2331 10.2292Z" fill="black">
</path>
<path d="M14.1432 11.9059L11.2261 10.2298C11.1985 10.216 11.164 10.2022 11.1365 10.1953L7.875 15.7825C7.90258 15.817 7.94609 15.8673 7.98056 15.888L10.8813 17.548C10.9641 17.5963 11.0606 17.6101 11.1503 17.5825L14.219 11.968C14.1983 11.9404 14.1708 11.9197 14.1432 11.9059Z" fill="black">
</path>
<path d="M14.136 15.8715C14.2187 15.8231 14.2933 15.7327 14.2933 15.6236L11.1154 10.1879C11.0326 10.1741 10.943 10.181 10.8671 10.2293L7.9707 11.8985L11.0947 17.5958C11.1361 17.5889 11.1843 17.5751 11.2257 17.5544L14.136 15.8715Z" fill="url(#:r11:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":r11:paint0" x1="12.2396" x2="9.61385" y1="11.4775" y2="16.8331">
<stop stop-color="#3F873F">
</stop>
<stop offset="0.3296" stop-color="#3F8B3D">
</stop>
<stop offset="0.6367" stop-color="#3E9638">
</stop>
<stop offset="0.9341" stop-color="#3DA92E">
</stop>
<stop offset="1" stop-color="#3DAE2B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r11:paint1" x1="10.6159" x2="17.9826" y1="14.2811" y2="8.83932">
<stop offset="0.1376" stop-color="#3F873F">
</stop>
<stop offset="0.4016" stop-color="#52A044">
</stop>
<stop offset="0.7129" stop-color="#64B749">
</stop>
<stop offset="0.9081" stop-color="#6ABF4B">
</stop>
</lineargradient>
<lineargradient gradientunits="userSpaceOnUse" id=":r11:paint2" x1="7.69907" x2="14.4172" y1="13.8874" y2="13.8874">
<stop offset="0.0919165" stop-color="#6ABF4B">
</stop>
<stop offset="0.2871" stop-color="#64B749">
</stop>
<stop offset="0.5984" stop-color="#52A044">
</stop>
<stop offset="0.8624" stop-color="#3F873F">
</stop>
</lineargradient>
<clippath id="clip0_2131_12968">
<rect fill="white" height="18.427" transform="translate(0 6)" width="30">
</rect>
</clippath>
</defs>
</svg>
<div class="leafygreen-ui-obh8q1">
<div class="lg-ui-select-menu-0000 leafygreen-ui-17aj16e" data-lgid="lg-select-button_text">
Node.js
</div>
</div>
<svg alt="" aria-hidden="true" class="leafygreen-ui-fn50nl" height="16" role="presentation" viewbox="0 0 16 16" width="16">
<path d="M8.67903 10.7962C8.45271 11.0679 8.04729 11.0679 7.82097 10.7962L4.63962 6.97649C4.3213 6.59428 4.5824 6 5.06866 6L11.4313 6C11.9176 6 12.1787 6.59428 11.8604 6.97649L8.67903 10.7962Z" fill="currentColor">
</path>
</svg>
</div>
</button>
<div aria-live="polite" aria-relevant="all" class="leafygreen-ui-11ydt2g" data-lgid="lg-form_field-feedback" data-testid="lg-form_field-feedback">
</div>
</div>
</div>
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
|
Subsets and Splits